我很难组织我的代码,因此我决定在初始化过程中实施bluebird,但唯一的目的是组织,所以我不知道如何在一个中调用resolve我的过程。
我有:
Configuration(app).then(Apps).then(Routes)
Configuration -> Turn my configuration object global.
Apps -> configure the uses, sets and uses of express
Routes -> create the routes
问题是。如何在此文件中应用新承诺的逻辑:
var Apps;
Apps = function(app) {
app.engine('.html', ejs.renderFile);
app.set('views', path.join(__dirname, '../../client/views'));
app.set('view engine', 'ejs');
app.use(body.json());
app.use(body.urlencoded({
extended: false
}));
app.use(cookie());
app.use(express["static"](path.join(__dirname, '../../client/public')));
app.use(express["static"](path.join(__dirname, '../../client/app')));
app.use(function(request, response, next) {
response.header('Access-Control-Allow-Origin', GLOBAL.config.cors.origin);
response.header('Access-Control-Allow-Methods', GLOBAL.config.cors.methods);
response.header('Access-Control-Allow-Headers', GLOBAL.config.cors.headers);
next();
});
app.use(session({
secret: '04Eq27Sgg0BDlgfRmarMar1234689007-James-Bond'
}));
};
我没有任何逻辑:如果可以,请拨打resolve
,如果没有,请拨打reject
。所以,这样做是愚蠢的:
var Apps;
Apps = function(app) {
return new Promise(resolve, reject) {
app.engine('.html', ejs.renderFile);
app.set('views', path.join(__dirname, '../../client/views'));
app.set('view engine', 'ejs');
app.use(body.json());
app.use(body.urlencoded({
extended: false
}));
app.use(cookie());
app.use(express["static"](path.join(__dirname, '../../client/public')));
app.use(express["static"](path.join(__dirname, '../../client/app')));
app.use(function(request, response, next) {
response.header('Access-Control-Allow-Origin', GLOBAL.config.cors.origin);
response.header('Access-Control-Allow-Methods', GLOBAL.config.cors.methods);
response.header('Access-Control-Allow-Headers', GLOBAL.config.cors.headers);
next();
});
app.use(session({
secret: '04Eq27Sgg0BDlgfRmarMar1234689007-James-Bond'
}));
resolve()
}
};
我的问题是。在这种情况下,我能做什么???