mirror of
https://github.com/abrendan/MicDropMessages.git
synced 2025-08-25 22:12:02 +02:00
Initial commit
This commit is contained in:
31
node_modules/server/router/generic.js
generated
vendored
Normal file
31
node_modules/server/router/generic.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
const join = require('../src/join');
|
||||
const parse = require('./parse');
|
||||
const params = require('./path-to-regexp-wrap')();
|
||||
|
||||
// Generic request handler
|
||||
module.exports = (method, ...all) => {
|
||||
|
||||
// Extracted or otherwise it'd shift once per call; also more performant
|
||||
const { path, middle } = parse(all);
|
||||
|
||||
const match = params(path || '');
|
||||
|
||||
return async ctx => {
|
||||
|
||||
// A route should be solved only once per request
|
||||
if (ctx.req.solved) return;
|
||||
|
||||
// Only for the correct method
|
||||
if (method !== ctx.req.method) return;
|
||||
|
||||
// Only do this if the correct path
|
||||
ctx.req.params = match(ctx.req.path);
|
||||
if (!ctx.req.params) return;
|
||||
ctx.params = ctx.req.params;
|
||||
|
||||
// Perform this promise chain
|
||||
await join(middle)(ctx);
|
||||
|
||||
ctx.req.solved = true;
|
||||
};
|
||||
};
|
Reference in New Issue
Block a user