gpt4 book ai didi

javascript - NodeJs错误v-host中间件

转载 作者:行者123 更新时间:2023-12-03 09:35:58 24 4
gpt4 key购买 nike

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

这是我的测试代码:

/home/*****/Scrivania/server/server.js

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

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

app.listen(3000);

/home/****/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

提前感谢您的回答。

最佳答案

它的问题正是错误消息所说的错误:大多数中间件(如虚拟主机)不再与 Express 捆绑在一起,必须单独安装。请参阅 https://github.com/senchalabs/connect#middleware。

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

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

关于javascript - NodeJs错误v-host中间件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31337859/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com