first version
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is failing Details

This commit is contained in:
Jay 2019-12-18 10:59:34 +08:00
commit 5b85b57e99
13 changed files with 2067 additions and 0 deletions

1
.dockerignore Normal file
View File

@ -0,0 +1 @@
node_modules/

17
.drone.yml Normal file
View File

@ -0,0 +1,17 @@
kind: pipeline
name: default
steps:
- name: gitea_release
image: plugins/gitea-release
settings:
api_key:
from_secret: gitea_token
base_url: https://git.trj.tw
files: ./*
checksum:
- md5
- sha1
- sha256
when:
event: tag

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules/

6
Dockerfile Normal file
View File

@ -0,0 +1,6 @@
FROM node:lts-alpine
LABEL maintainer="Jay <admin@trj.tw>"
WORKDIR /data
COPY . .
RUN npm install
CMD ["npm", "start"]

6
config/index.js Normal file
View File

@ -0,0 +1,6 @@
const env = process.env
module.exports = {
server: {
port: env.SERVER_PORT || 10230
}
}

7
controller/index.js Normal file
View File

@ -0,0 +1,7 @@
const controller = {}
module.exports = controller
controller.healthCheck = async (ctx, next) => {
ctx.body = 'ok'
ctx.status = 200
}

4
index.js Normal file
View File

@ -0,0 +1,4 @@
require('dotenv').config()
require('module-alias/register')
require('./server.js')

12
jsconfig.json Normal file
View File

@ -0,0 +1,12 @@
{
"compilerOptions": {
"moduleResolution": "node",
"baseUrl": ".",
"paths": {
"@libs/*": ["libs/*"],
"@config/*": ["config/*"],
"@route/*": ["route/*"],
"@controller/*": ["controller/*"]
}
}
}

2
libs/index.js Normal file
View File

@ -0,0 +1,2 @@
const libs = {}
module.exports = libs

1953
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

29
package.json Normal file
View File

@ -0,0 +1,29 @@
{
"name": "koa-template",
"version": "1.0.0",
"description": "koa server template",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "Jay <admin@trj.tw>",
"license": "MIT",
"dependencies": {
"@koa/cors": "^3.0.0",
"@koa/router": "^8.0.5",
"dotenv": "^8.2.0",
"koa": "^2.11.0",
"koa-body": "^4.1.1",
"koa-logger": "^3.2.1",
"koa-session2": "github:otakukaze/koa-session2#master",
"module-alias": "^2.2.2"
},
"_moduleAliases": {
"@libs": "libs",
"@config": "config",
"@route": "route",
"@controller": "controller"
}
}

7
route/index.js Normal file
View File

@ -0,0 +1,7 @@
const Router = require('@koa/router')
const r = new Router()
module.exports = r
const controller = require('@controller/index.js')
r.get('/', controller.healthCheck)

22
server.js Normal file
View File

@ -0,0 +1,22 @@
const Koa = require('koa')
const app = new Koa()
const config = require('@config/index.js')
const server = app.listen(config.server.port, () => {
console.log(`server start on port ${server.address().port}`)
})
module.exports = server
// load middleware module
const koaLogger = require('koa-logger')
const koaCors = require('@koa/cors')
const rootRouter = require('@route/index.js')
app.use(koaLogger())
app.use(koaCors({
credentials: true,
// allow all origin
origin: ctx => ctx.get('origin')
}))
app.use(rootRouter.allowedMethods())
app.use(rootRouter.routes())