Express 版本是最新的。
这是 app.js 文件,它被另一个 app.js 文件使用:
"use strict";
var express = require('express'), engine = require('ejs-locals');
var path = require('path'), map = require('../../app').map;
var register = require('./routes/register').register;
var profile = require('./routes/profile').profile;
var login = require('./routes/login').login;
var app = module.exports = express();
app.configure(function() {
app.engine('ejs', engine);
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use('/assets', express.static(path.join(__dirname, 'assets')));
});
app.configure('development', function() {
app.use(express.errorHandler());
});
app.map = map;
app.map(app, {
'/seller': {
'/password': {
get: login.forgot, // Looks in the correct place /assets/css/... etc.
'/forgot': {
get: login.forgot // Looks in wrong place /seller/assets/... etc.
},
'/reset': {
get: login.reset
}
}
}
});
当请求 GET 时http://localhost:3000/seller/password
,Express 在正确的位置查找静态文件,即/assets/css/。
但是当请求 GET 时http://localhost:3000/seller/password/forgot
,Express 会在错误的位置查找静态文件,即/seller/assets/css,它甚至不存在。
这是地图功能。它取自 Express路线图示例。
function route_map(app, a, route) {
route = route || '';
for (var key in a) {
switch (typeof a[key]) {
case 'object': // { '/path': { ... }}
app.map(app, a[key], route + key);
break;
case 'function': // get: function(){ ... }
app[key](route, a[key]);
break;
}
}
}