From daeda0c459377002de9764e9fb43515e7904f15f Mon Sep 17 00:00:00 2001 From: chertik77 Date: Sun, 25 Aug 2024 12:40:31 +0100 Subject: [PATCH] refactor: remove api prefix on production --- .env.example | 1 + README.md | 2 +- app/app.ts | 14 ++++++++------ app/typings/environment.d.ts | 1 + swagger.json | 2 +- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/.env.example b/.env.example index 28f81dd..21a1cd6 100644 --- a/.env.example +++ b/.env.example @@ -4,6 +4,7 @@ CLOUDINARY_CLOUD_NAME= DATABASE_URL= ALLOWED_ORIGINS= PORT= +API_PREFIX= ACCESS_JWT_SECRET= REFRESH_JWT_SECRET= EMAIL_PORT= diff --git a/README.md b/README.md index ee086dd..c8a168f 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Welcome to the Task Pro App Backend, the powerhouse behind the ultimate tool for ![Screenshot 2024-06-25 at 17 31 06](https://github.com/chertik77/TaskPro-backend/assets/129002577/80c66817-1151-4a9b-91b0-342b387f3810) -_Link to the swagger docs:_ https://api.taskpro.uk/api/docs +_Link to the swagger docs:_ https://api.taskpro.uk/docs _Link to the frontend repo:_ https://github.com/chertik77/TaskPro-frontend diff --git a/app/app.ts b/app/app.ts index 5c09d93..f411908 100644 --- a/app/app.ts +++ b/app/app.ts @@ -24,17 +24,19 @@ export type ResponseError = Error & { export const app = express() +const apiPrefix = process.env.API_PREFIX + app.use(logger('dev')) app.use(cors({ origin: process.env.ALLOWED_ORIGINS?.split(',') })) app.use(express.json()) app.disable('x-powered-by') -app.use('/api/docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument)) -app.use('/api/auth', authRouter) -app.use('/api/user', userRouter) -app.use('/api/board', boardRouter) -app.use('/api/column', columnRouter) -app.use('/api/card', cardRouter) +app.use(`${apiPrefix}/docs`, swaggerUi.serve, swaggerUi.setup(swaggerDocument)) +app.use(`${apiPrefix}/auth`, authRouter) +app.use(`${apiPrefix}/user`, userRouter) +app.use(`${apiPrefix}/board`, boardRouter) +app.use(`${apiPrefix}/column`, columnRouter) +app.use(`${apiPrefix}/card`, cardRouter) app.use((_, res) => { res.status(404).json({ message: 'Not found' }) diff --git a/app/typings/environment.d.ts b/app/typings/environment.d.ts index a351c8f..5b2a8d5 100644 --- a/app/typings/environment.d.ts +++ b/app/typings/environment.d.ts @@ -9,6 +9,7 @@ declare global { REFRESH_JWT_SECRET: string ALLOWED_ORIGINS: string PORT: number + API_PREFIX: string EMAIL_HOST: string EMAIL_PORT: number EMAIL_USER: string diff --git a/swagger.json b/swagger.json index a4ef16b..b712757 100644 --- a/swagger.json +++ b/swagger.json @@ -7,7 +7,7 @@ }, "servers": [ { "url": "http:localhost:7000/api - Development" }, - { "url": "https://api.taskpro.uk/api - Production" } + { "url": "https://api.taskpro.uk - Production" } ], "paths": { "/auth/signup": {