Skip to content

Commit 6a717c3

Browse files
Add API to docker-compose
1 parent 3c42f5b commit 6a717c3

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM node:16.13
2+
3+
RUN mkdir /api
4+
WORKDIR /api
5+
6+
COPY package.json /api
7+
COPY yarn.lock /api
8+
9+
RUN yarn install

docker-compose.yaml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1-
version: "3.5"
1+
version: "3.9"
22

33
services:
4+
api:
5+
build: .
6+
container_name: node-api-boilerplate
7+
command: yarn dev
8+
volumes:
9+
- .:/api
10+
ports:
11+
- 3000:3000
12+
environment:
13+
HOST: 0.0.0.0
14+
SWAGGER_HOST: localhost
15+
DB_HOST: mongodb://node-api-boilerplate-mongodb:27017
16+
417
mongodb:
5-
container_name: blog-mongodb
18+
container_name: node-api-boilerplate-mongodb
619
image: mongo:4.2
720
ports:
821
- 27017:27017

src/_boot/swagger.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ type SwaggerConfig = {
77
swagger: {
88
title: string;
99
version: string;
10+
host: string;
1011
basePath: string;
1112
docEndpoint: string;
1213
};
@@ -19,7 +20,7 @@ const swagger = makeModule('swagger', async ({ container: { build }, config: { h
1920
title: swagger.title,
2021
version: swagger.version,
2122
},
22-
host: `${http.host}:${http.port}`,
23+
host: `${swagger.host}:${http.port}`,
2324
basePath: swagger.basePath,
2425
},
2526
apis: [resolve(__dirname, '../**/interface/http/**/*.yaml'), resolve(__dirname, '../**/interface/http/**/*.ts')],

src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const config: Configuration = {
2121
swagger: {
2222
title: 'Blog API',
2323
version: '1.0.0',
24+
host: envString('SWAGGER_HOST', envString('HOST', 'localhost')),
2425
basePath: '/api',
2526
docEndpoint: '/api-docs',
2627
},

0 commit comments

Comments
 (0)