first version
This commit is contained in:
commit
5b85b57e99
1
.dockerignore
Normal file
1
.dockerignore
Normal file
@ -0,0 +1 @@
|
|||||||
|
node_modules/
|
17
.drone.yml
Normal file
17
.drone.yml
Normal 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
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
node_modules/
|
6
Dockerfile
Normal file
6
Dockerfile
Normal 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
6
config/index.js
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
const env = process.env
|
||||||
|
module.exports = {
|
||||||
|
server: {
|
||||||
|
port: env.SERVER_PORT || 10230
|
||||||
|
}
|
||||||
|
}
|
7
controller/index.js
Normal file
7
controller/index.js
Normal 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
4
index.js
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
require('dotenv').config()
|
||||||
|
require('module-alias/register')
|
||||||
|
|
||||||
|
require('./server.js')
|
12
jsconfig.json
Normal file
12
jsconfig.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"baseUrl": ".",
|
||||||
|
"paths": {
|
||||||
|
"@libs/*": ["libs/*"],
|
||||||
|
"@config/*": ["config/*"],
|
||||||
|
"@route/*": ["route/*"],
|
||||||
|
"@controller/*": ["controller/*"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
2
libs/index.js
Normal file
2
libs/index.js
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
const libs = {}
|
||||||
|
module.exports = libs
|
1953
package-lock.json
generated
Normal file
1953
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
29
package.json
Normal file
29
package.json
Normal 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
7
route/index.js
Normal 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
22
server.js
Normal 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())
|
Loading…
Reference in New Issue
Block a user