正在显示
1 个修改的文件
包含
0 行增加
和
110 行删除
config/app.js
已删除
100644 → 0
1 | - | |
2 | -// # config - app | |
3 | - | |
4 | -var express = require('express') | |
5 | -var flash = require('connect-flash') | |
6 | -var development = require('./development') | |
7 | -var production = require('./production') | |
8 | -var passport = require('passport') | |
9 | -var settings = require('./settings') | |
10 | -var routes = require('./routes') | |
11 | -var ioc = require('electrolyte') | |
12 | -var session = require('express-session') | |
13 | -var methodOverride = require('method-override') | |
14 | -var errorHandler = require('errorhandler') | |
15 | -var serveFavicon = require('serve-favicon') | |
16 | -var cookieParser = require('cookie-parser') | |
17 | -var bodyParser = require('body-parser') | |
18 | -var dataNode = require('../lib/data-node') | |
19 | -var helmet = require('helmet') | |
20 | - | |
21 | -module.exports = function(lib, callback) { | |
22 | - | |
23 | - var app = express() | |
24 | - | |
25 | - // set the environment | |
26 | - app.set('env', lib.config.env) | |
27 | - | |
28 | - // disable x-powered-by | |
29 | - app.disable('x-powered-by') | |
30 | - | |
31 | - // trust proxy | |
32 | - app.enable('trust proxy') | |
33 | - | |
34 | - // set the default views directory | |
35 | - app.set('views', lib.config.viewsDir) | |
36 | - | |
37 | - // make jade the default view engine | |
38 | - app.set('view engine', 'jade') | |
39 | - | |
40 | - // make jade pretty | |
41 | - app.locals.pretty = true | |
42 | - | |
43 | - // use helmet for security | |
44 | - app.use(helmet.defaults()) | |
45 | - | |
46 | - // ignore GET /favicon.ico | |
47 | - app.use(serveFavicon(lib.config.favicon)) | |
48 | - | |
49 | - // environment configs | |
50 | - switch(lib.config.env){ | |
51 | - case 'development': | |
52 | - development(lib, app) | |
53 | - break | |
54 | - case 'production': | |
55 | - production(lib, app) | |
56 | - break | |
57 | - } | |
58 | - | |
59 | - // pass a secret to cookieParser() for signed cookies | |
60 | - app.use(cookieParser(lib.config.cookieParser)) | |
61 | - | |
62 | - // parse request bodies | |
63 | - app.use(bodyParser()) | |
64 | - | |
65 | - // support _method (PUT in forms etc) | |
66 | - app.use(methodOverride()) | |
67 | - | |
68 | - // add req.session cookie support | |
69 | - app.use(session(lib.config.session)) | |
70 | - | |
71 | - // add flash message support | |
72 | - app.use(flash()) | |
73 | - | |
74 | - // add dynamic helpers for views | |
75 | - app.use(function(req, res, next) { | |
76 | - res.locals.req = req | |
77 | - res.locals.messages = { | |
78 | - success: req.flash('success'), | |
79 | - error: req.flash('error'), | |
80 | - info: req.flash('info'), | |
81 | - warning: req.flash('warning') | |
82 | - } | |
83 | - next() | |
84 | - }) | |
85 | - | |
86 | - // add support for authentication | |
87 | - app.use(passport.initialize()) | |
88 | - app.use(passport.session()) | |
89 | - passport.use(lib.db.model('User').createStrategy()) | |
90 | - passport.serializeUser(lib.db.model('User').serializeUser()) | |
91 | - passport.deserializeUser(lib.db.model('User').deserializeUser()) | |
92 | - | |
93 | - // load the routes | |
94 | - routes(lib, app)() | |
95 | - | |
96 | - // static server | |
97 | - app.use(express.static(lib.config.publicDir, lib.config.staticServer)) | |
98 | - | |
99 | - // error handling | |
100 | - app.use(errorHandler()) | |
101 | - | |
102 | - callback(null, app) | |
103 | - | |
104 | - return { | |
105 | - app: app, | |
106 | - lib: lib | |
107 | - } | |
108 | - | |
109 | -} | |
110 | - |
请
注册
或
登录
后发表评论