Skip to content

Commit cff0816

Browse files
committed
🐳 1.0.0, initial version
0 parents  commit cff0816

File tree

19 files changed

+4699
-0
lines changed

19 files changed

+4699
-0
lines changed

.dockerignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.git
2+
node_modules
3+
npm-debug.log
4+
*.md
5+
test
6+
docs
7+
Dockerfile
8+
coverage
9+
LICENSE
10+
.eslintrc
11+
.gitignore
12+
.nvmrc
13+
14+
.env*
15+
.editorconfig

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# http://editorconfig.org
2+
3+
root = true
4+
5+
[*]
6+
charset = utf-8
7+
indent_style = space
8+
indent_size = 2
9+
end_of_line = lf
10+
insert_final_newline = true
11+
trim_trailing_whitespace = true
12+
13+
[*.md]
14+
insert_final_newline = false
15+
trim_trailing_whitespace = false

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
HTTP_PORT=3000
2+
HTTP_HOST=0.0.0.0

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
3+
.env.local

Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM node:14-alpine
2+
3+
LABEL maintainer="[email protected]"
4+
5+
ENV NODE_ENV=production
6+
7+
EXPOSE 3000
8+
9+
# Run as an unprivileged user.
10+
RUN addgroup -S webapp && adduser -S -G webapp webapp
11+
RUN mkdir /app && chown webapp /app
12+
USER webapp
13+
14+
WORKDIR /app
15+
ENTRYPOINT ["yarn", "start"]
16+
17+
COPY package.json yarn.lock /app/
18+
19+
RUN yarn
20+
21+
COPY . .

LICENSES

Lines changed: 2938 additions & 0 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "docker-ipdb",
3+
"version": "1.0.0",
4+
"main": "server.js",
5+
"repository": "[email protected]:metowolf/docker-ipdb.git",
6+
"author": "metowolf <[email protected]>",
7+
"license": "MIT",
8+
"scripts": {
9+
"dev": "nodemon server.js"
10+
},
11+
"dependencies": {
12+
"@ipdb/database": "^2019.7.3",
13+
"@ipdb/range": "^0.1.1",
14+
"dotenv-flow": "^3.2.0",
15+
"ipdb": "^0.3.3",
16+
"koa": "^2.13.0",
17+
"koa-helmet": "^5.2.0",
18+
"koa-pino-logger": "^3.0.0",
19+
"koa-router": "^9.1.0",
20+
"koa2-cors": "^2.0.6",
21+
"pino": "^6.3.2",
22+
"pino-pretty": "^4.0.0",
23+
"qqwry.ipdb": "^2020.7.5"
24+
},
25+
"devDependencies": {
26+
"nodemon": "^2.0.4"
27+
}
28+
}

server.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const config = require('./src/config')
2+
const { logger } = require('./src/middleware/logger')
3+
const app = require('./src/app')
4+
5+
app.listen(config.http.port, config.http.host)
6+
logger.info(`Running on port: ${config.http.port}`)

src/app.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const cors = require('koa2-cors')
2+
const helmet = require('koa-helmet')
3+
const Koa = require('koa')
4+
const { requestLogger } = require('./middleware/logger')
5+
const { responseTime, errors } = require('./middleware')
6+
const { v1 } = require('./services')
7+
8+
const app = new Koa()
9+
10+
// disable console.errors for pino
11+
app.silent = true
12+
13+
// Error handler
14+
app.use(errors)
15+
16+
// HTTP header security
17+
app.use(helmet())
18+
19+
// Enable CORS for all routes
20+
app.use(cors({
21+
origin: '*',
22+
allowMethods: ['GET', 'POST', 'PATCH', 'DELETE'],
23+
allowHeaders: ['Content-Type', 'Accept'],
24+
exposeHeaders: ['x-api-response-time']
25+
}))
26+
27+
// Set header with API response time
28+
app.use(responseTime)
29+
30+
// Request logging
31+
app.use(requestLogger)
32+
33+
// V1 routes
34+
app.use(v1.routes())
35+
36+
module.exports = app

src/config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require('dotenv-flow').config()
2+
3+
module.exports = {
4+
http: {
5+
port: parseInt(process.env.HTTP_PORT || 3000, 10),
6+
host: process.env.HTTP_HOST || 'localhost'
7+
}
8+
}

0 commit comments

Comments
 (0)