mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
template: problem_detail
This commit is contained in:
1 parent
2e23d05a59
commit
ffa193b5dd
43 files changed
+265
-242
No files matched your search
@@ -13,37 +13,7 @@ let server = http.createServer(app.callback());
|
||||
app.keys = options.session.keys;
|
||||
app.use(morgan(':method :url :status :res[content-length] - :response-time ms'));
|
||||
app.use(Body());
|
||||
|
||||
let router = new Router();
|
||||
let contexts = [];
|
||||
function CONTEXT() {
|
||||
this.router = new Router();
|
||||
/**
|
||||
* @param {import('koa').Middleware} middleware
|
||||
*/
|
||||
function MIDDLEWARE(middleware) {
|
||||
router.use(middleware);
|
||||
}
|
||||
/**
|
||||
* @param {string} route
|
||||
* @param {...import('koa').Middleware} handler
|
||||
*/
|
||||
function GET(route, ...handler) {
|
||||
router.get(route, ...handler);
|
||||
}
|
||||
/**
|
||||
* @param {string} route
|
||||
* @param {...import('koa').Middleware} handler
|
||||
*/
|
||||
function POST(route, ...handler) {
|
||||
router.post(route, ...handler);
|
||||
}
|
||||
this.MIDDLEWARE = MIDDLEWARE;
|
||||
this.GET = GET;
|
||||
this.POST = POST;
|
||||
contexts.push(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import('koa').Middleware} middleware
|
||||
@@ -78,15 +48,12 @@ function SOCKET(prefix, handler) {
|
||||
sock.on('connection', handler);
|
||||
sock.installHandlers(server);
|
||||
}
|
||||
exports.CONTEXT = CONTEXT;
|
||||
exports.MIDDLEWARE = MIDDLEWARE;
|
||||
exports.GET = GET;
|
||||
exports.POST = POST;
|
||||
exports.SOCKET = SOCKET;
|
||||
exports.start = function start() {
|
||||
app.use(router.routes()).use(router.allowedMethods());
|
||||
for (let c of contexts)
|
||||
app.use(c.router.routes()).use(c.router.allowedMethods());
|
||||
app.listen(options.listen.port);
|
||||
console.log('Server listening at: %s', options.listen.port);
|
||||
};
|
||||
Reference in new issue
Block a user