From cfae285d446c343cdebe921dcd09fd7ddd1a5ab3 Mon Sep 17 00:00:00 2001 From: Sugui Date: Fri, 8 Dec 2023 14:05:20 +0100 Subject: [PATCH] first commit --- .gitignore | 2 ++ Dockerfile | 40 ++++++++++++++++++++++++++++++++++++++++ README.md | 15 +++++++++++++++ index.ts | 13 +++++++++++++ package.json | 17 +++++++++++++++++ tsconfig.json | 22 ++++++++++++++++++++++ 6 files changed, 109 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 index.ts create mode 100644 package.json create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c2b8d7c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +bun.lockb \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1f136b0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,40 @@ +# Dockerfile + +# use the official Bun image +# see all versions at https://hub.docker.com/r/oven/bun/tags +FROM oven/bun:1 as base +WORKDIR /usr/src/app + +# install dependencies into temp folder +# this will cache them and speed up future builds +FROM base AS install +RUN mkdir -p /temp/dev +COPY package.json bun.lockb /temp/dev/ +RUN cd /temp/dev && bun install + +# install with --production (exclude devDependencies) +RUN mkdir -p /temp/prod +COPY package.json bun.lockb /temp/prod/ +RUN cd /temp/prod && bun install --production + +# copy node_modules from temp folder +# then copy all (non-ignored) project files into the image +FROM install AS prerelease +COPY --from=install /temp/dev/node_modules node_modules +COPY . . + +# [optional] tests & build +# ENV NODE_ENV=production +# RUN bun test +# RUN bun run build + +# copy production dependencies and source code into final image +FROM base AS release +COPY --from=install /temp/prod/node_modules node_modules +COPY --from=prerelease /usr/src/app/index.ts . +COPY --from=prerelease /usr/src/app/package.json . + +# run the app +USER bun +EXPOSE 3000/tcp +CMD ["bun", "run", "index.ts"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..5998e95 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# fib-api + +To install dependencies: + +```bash +bun install +``` + +To run: + +```bash +bun run index.ts +``` + +This project was created using `bun init` in bun v1.0.13. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime. diff --git a/index.ts b/index.ts new file mode 100644 index 0000000..fd96f7b --- /dev/null +++ b/index.ts @@ -0,0 +1,13 @@ +import express from "express"; + +const app = express(); + +// Hello World GET endpoint +app.get("/", (_, res) => { + res.send("Hello World!"); +}); + +// Set the default port to 3000, or use the PORT environment variable +const port = process.env.PORT || 3000; + +app.listen(port, () => console.log(`Express server listening on port ${port}`)); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..eaac0ed --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "fib-api", + "module": "index.ts", + "type": "module", + "devDependencies": { + "bun-types": "latest" + }, + "peerDependencies": { + "typescript": "^5.0.0" + }, + "dependencies": { + "@types/express": "^4.17.21", + "@types/mongoose": "^5.11.97", + "express": "^4.18.2", + "mongoose": "^8.0.3" + } +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..7556e1d --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "lib": ["ESNext"], + "module": "esnext", + "target": "esnext", + "moduleResolution": "bundler", + "moduleDetection": "force", + "allowImportingTsExtensions": true, + "noEmit": true, + "composite": true, + "strict": true, + "downlevelIteration": true, + "skipLibCheck": true, + "jsx": "react-jsx", + "allowSyntheticDefaultImports": true, + "forceConsistentCasingInFileNames": true, + "allowJs": true, + "types": [ + "bun-types" // add Bun global + ] + } +}