From e4e708b36cef02f40c1125b715d3cbc7b754bf6f Mon Sep 17 00:00:00 2001 From: jd-apprentice Date: Fri, 13 Sep 2024 23:28:45 -0300 Subject: [PATCH] chore: running docker with typescript --- docker/Dockerfile | 22 +++++++--------------- package.json | 2 +- src/app/main.ts | 8 ++++---- src/app/routes/index.ts | 4 +--- 4 files changed, 13 insertions(+), 23 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 40087ba..907e639 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,5 +1,5 @@ FROM oven/bun:1 AS base -WORKDIR /usr/src/app +WORKDIR /bun FROM base AS install @@ -12,21 +12,13 @@ COPY package.json bun.lockb /temp/prod/ RUN cd /temp/prod && bun install --frozen-lockfile --production FROM base AS prerelease -COPY --from=install /temp/dev/node_modules node_modules -COPY . . - -ENV NODE_ENV=production -RUN bun run lint -RUN bun run build - -FROM base AS release COPY --from=install /temp/prod/node_modules node_modules -COPY --from=prerelease /usr/src/app/dist ./dist +COPY src src -RUN mkdir -p /usr/src/app/src/image/assets/images -RUN chown -R bun:bun /usr/src/app/src/image/assets/images -RUN chmod -R 600 /usr/src/app/src/image/assets/images +RUN mkdir -p /bun/src/image/assets/images +RUN chmod -R 600 /bun/src/image/assets/images +ENV NODE_ENV=production USER bun -EXPOSE 4000/tcp -ENTRYPOINT [ "bun", "dist/index.js" ] \ No newline at end of file +EXPOSE 4000 +CMD ["bun", "/bun/src/app/index.ts"] \ No newline at end of file diff --git a/package.json b/package.json index 309316d..5d8f790 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "1.0.0", "author": "jd-apprentice", "license": "MIT", - "main": "dist/app/index.js", + "main": "dist/index.js", "type": "module", "scripts": { "prebuild": "rm -rf dist", diff --git a/src/app/main.ts b/src/app/main.ts index 3153cef..e00a152 100644 --- a/src/app/main.ts +++ b/src/app/main.ts @@ -4,7 +4,7 @@ import express from 'express'; import cors from 'cors'; // Internal Modules -import routes from './routes/index'; +import { routes } from './routes/index'; // Express const app = express(); @@ -13,8 +13,8 @@ app.use(express.urlencoded({ extended: false })); app.use(cors()); app.use(helmet()); app.use('/api', routes); -app.use('/', (req, res) => { - res.status(200).json({ message: 'Allo! Catch-all route.' }); -}); +app.use('/', (req, res) => + res.status(200).json({ message: 'Allo! Catch-all route.' }), +); export { app }; diff --git a/src/app/routes/index.ts b/src/app/routes/index.ts index 7830504..32c2628 100644 --- a/src/app/routes/index.ts +++ b/src/app/routes/index.ts @@ -6,7 +6,7 @@ import userRouter from "../../user/user-routes"; import tagRouter from "../../tag/tag-routes"; import imageRouter from "../../image/image-routes"; -const routes = Router(); +export const routes = Router(); routes.use("/images", imageRouter); routes.use("/user", userRouter); @@ -14,5 +14,3 @@ routes.use("/tags", tagRouter); routes.use("/", (req, res) => { res.status(200).json({ message: "Welcome to the Waifuland API" }); }); - -export default routes;