Skip to content

Commit f5b8a21

Browse files
authored
Docker compose configuration (#107)
* Docker compose configuration
1 parent 77ed325 commit f5b8a21

File tree

8 files changed

+40
-4
lines changed

8 files changed

+40
-4
lines changed

.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ Dockerfile*
77
.vscode
88
.travis.yml
99
README.md
10+
docker-compose.yml
11+
request.http
12+
nodemon.json
13+
.github
14+
.env.sample

.env.sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SERVER_PORT=3001

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:16 as buildImg
1+
FROM node:16-alpine as buildImg
22
WORKDIR /usr/src/app
33
COPY package.json ./
44
COPY tsconfig.json ./
@@ -7,7 +7,7 @@ COPY src ./src
77
RUN npm install
88
RUN npm run build
99

10-
FROM node:16
10+
FROM node:16-alpine
1111
WORKDIR /usr/src/app
1212
COPY package.json ./
1313
RUN npm install

docker-compose.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: "3.9"
2+
services:
3+
api:
4+
container_name: express-api
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
image: express-api
9+
restart: always
10+
ports:
11+
- "3001:${SERVER_PORT}"

package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"homepage": "https://github.com/spinsage/express-typescript-starter-rest#readme",
2727
"dependencies": {
2828
"cors": "^2.8.5",
29+
"dotenv": "^10.0.0",
2930
"express": "^4.17.2"
3031
},
3132
"devDependencies": {

request.http

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
GET http://localhost:3001/
2+
###

src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import express from "express";
2-
import bodyParser from "body-parser";
32
import cors from "cors";
43
import { appRouter } from "./routes";
4+
import dotenv from "dotenv";
5+
6+
dotenv.config();
57

68
const port = process.env.PORT || 3001;
79

@@ -12,6 +14,6 @@ app.use(express.json());
1214
app.use(cors());
1315
app.use("/", appRouter);
1416

15-
app.listen(port, () => {
17+
app.listen(Number(port), "0.0.0.0", () => {
1618
console.log("server started at http://localhost: %s", port);
1719
});

0 commit comments

Comments
 (0)