diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 52a2c05..9dbede0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -26,4 +26,5 @@ build: # This job runs in the build stage, which runs first. before_script: script: - echo "Compiling the code..." + - npm run build - echo "Compile complete." \ No newline at end of file diff --git a/package.json b/package.json index 885e0de..2d59807 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,8 @@ "license": "ISC", "description": "", "dependencies": { + "@fastify/swagger": "^9.6.1", + "@fastify/swagger-ui": "^5.2.3", "dotenv": "^17.2.3", "fastify": "^5.6.2", "fastify-postgres": "^3.6.0", diff --git a/src/app.ts b/src/app.ts new file mode 100644 index 0000000..2e2c91c --- /dev/null +++ b/src/app.ts @@ -0,0 +1,17 @@ +import Fastify from 'fastify'; +import fastifyPostgres from 'fastify-postgres'; +import { registerSwagger } from './utils/plugin/swagger'; +import dotenv from 'dotenv'; + +dotenv.config(); + +export async function buildApp() { + + const app = Fastify(); + await app.register(fastifyPostgres, { + connectionString: `postgresql://${process.env.PGUSER}:${process.env.PGPASSWORD}@${process.env.PGHOST}:${process.env.PGPORT}/${process.env.PGDATABASE}` + }) + await registerSwagger(app); + + return app; +} \ No newline at end of file diff --git a/src/route/user.route.ts b/src/route/user.route.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/server.ts b/src/server.ts index e69de29..441535c 100644 --- a/src/server.ts +++ b/src/server.ts @@ -0,0 +1,14 @@ +import { buildApp } from './app'; + +const start = async () => { + try { + const app = await buildApp(); + await app.listen({ port: 3000 }); + console.log(`Server running on port ${process.env.PORT}`); + } catch (err) { + console.error(err); + process.exit(1); + } +} + +start(); \ No newline at end of file diff --git a/src/utils/plugin/swagger.ts b/src/utils/plugin/swagger.ts new file mode 100644 index 0000000..56167a6 --- /dev/null +++ b/src/utils/plugin/swagger.ts @@ -0,0 +1,33 @@ +import { FastifyInstance } from "fastify"; +import fastifySwagger from "@fastify/swagger"; +import fastifySwaggerUi from "@fastify/swagger-ui"; + +export async function registerSwagger(fastify: FastifyInstance) { + await fastify.register(fastifySwagger, { + openapi: { + info: { + title: "API Docs", + description: "API documentation for Fastify server", + version: "1.0.0" + }, + servers: [ + { + url: "http://localhost:3000", + description: "Local Development", + }, + { + url: "https://api.scheduler.bkdhome.p-e.kr", + description: "Production Server" + } + ] + } + }); + + await fastify.register(fastifySwaggerUi, { + routePrefix: "/docs", + uiConfig: { + docExpansion: "none", + deepLinking: false + } + }); +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index a2adbfa..53df809 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,14 +1,17 @@ { "compilerOptions": { "target": "esnext", - "module": "CommonJS", "lib": ["ESNext"], "outDir": "dist", "rootDir": "src", "strict": true, "esModuleInterop": true, "resolveJsonModule": true, - "forceConsistentCasingInFileNames": true + "forceConsistentCasingInFileNames": true, + "skipLibCheck": true, + "noEmit": true, + "allowSyntheticDefaultImports": true, }, - "include": ["src/**/*"] + "include": ["src/**/*"], + "exclude": ["node_modules", "dist"] } \ No newline at end of file