NodeJs错误v-host中间件

时间:2015-07-10 09:55:23

标签: javascript node.js express virtualhost

我会用expressjs创建一个虚拟主机。 我启动服务器时遇到问题。

这是我的测试代码:

/家庭/ ***** / Scrivania /服务器/ server.js

var express = require('express'),
    app = express();

app.use(express.vhost('*.site1.com', require('./apps/appDue')));

app.listen(3000);

/家庭/ **** / Scrivania / appDue / index.js

var express = require('express'),
    app = express();

app.get('/', function(req, res) { 
    res.send('Home Page'); 
});

module.exports = app;

这是我启动服务器时的结果:

Error: Most middleware (like vhost) is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware.
    at Function.Object.defineProperty.get (/home/*****/Scrivania/server/node_modules/express/lib/express.js:99:13)
    at Object.<anonymous> (/home/****/Scrivania/server/server.js:4:17)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:902:3

提前感谢您的回答。

1 个答案:

答案 0 :(得分:1)

它的问题正是错误信息所说的 Error: Most middleware (like vhost) is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware.

您需要将该模块添加到package.json

https://www.npmjs.com/package/express-vhost