forked from javascript-tutorial/server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandlers.js
More file actions
executable file
·60 lines (45 loc) · 1.39 KB
/
handlers.js
File metadata and controls
executable file
·60 lines (45 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
'use strict';
const path = require('path');
const fs = require('fs');
let handlerNames = [
'engine/koa/static',
'engine/koa/requestId',
'engine/koa/requestLog',
'engine/koa/nocache',
// this middleware adds this.render method
// it is *before error*, because errors need this.render
'render',
// errors wrap everything
'engine/koa/error',
// this logger only logs HTTP status and URL
// before everything to make sure it log all
'engine/koa/accessLogger',
// pure node.js examples from tutorial
// before session
// before form parsing, csrf checking or whatever, bare node
'engine/koa/nodeExample',
// before anything that may deal with body
// it parses JSON & URLENCODED FORMS,
// it does not parse form/multipart
'engine/koa/bodyParser',
// parse FORM/MULTIPART
// (many tweaks possible, lets the middleware decide how to parse it)
'engine/koa/multipartParser',
// right after parsing body, make sure we logged for development
'engine/koa/verboseLogger',
'engine/koa/conditional',
process.env.NODE_ENV === 'development' && 'dev',
'engine/koa/tutorial',
'frontpage'
].filter(Boolean);
let handlers = {};
for (const name of handlerNames) {
let handlerPath = require.resolve(name);
if (handlerPath.endsWith('index.js')) {
handlerPath = path.dirname(handlerPath);
}
handlers[name] = {
path: handlerPath
}
}
module.exports = handlers;