'argument hostname required' 虚拟主机



AWS内部express vhost出现奇怪问题。每次我部署我得到一个错误在我的EB日志说:

TypeError: argument hostname is required
at vhost (/var/app/current/node_modules/vhost/index.js:39:11)
at Object.<anonymous> (/var/app/current/app.js:554:9)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
at internal/main/run_main_module.js:17:47
/var/app/current/node_modules/vhost/index.js:39
throw new TypeError('argument hostname is required')
^

如果我查看vhost模块index.js:第36行,我们有以下内容:

function vhost(hostname, handle) {
if (!hostname) {
throw new TypeError('argument hostname is required')
}
if (!handle) {
throw new TypeError('argument handle is required')
}
if (typeof handle !== 'function') {
throw new TypeError('argument handle must be a function')
}

甚至不像for句柄那样对主机名进行类型检查或任何检查,只是检查值是否传入。它显然在下面的代码中:

const app = express();
const register_app = express();
const nonadmin_app = express();
register_app.use(express.static(path.resolve(__dirname, './build/register')));
nonadmin_app.use(express.static(path.resolve(__dirname, './build/nonadmin')));    
app.use(vhost('register.<eb-dev-url>.elasticbeanstalk.com/', register_app))
app.use(vhost('nonadmin.<eb-dev-url>.elasticbeanstalk.com/', nonadmin_app))
app.use(vhost('api.<eb-dev-url>.elasticbeanstalk.com/', api))
register_app.get('/register', (req, res) => {
res.sendFile(path.resolve(__dirname, './build/register', 'index.html'));
})
nonadmin_app.get('/nonadmin', (req, res) => {
res.sendFile(path.resolve(__dirname, './build/nonadmin', 'index.html'));
})

我不相信这是vhost的问题,因为当使用register.localhost,nonadmin.localhostapi.localhost时,使用nodemon在本地运行此应用程序,它工作得很好。我还尝试使用.localhost后缀部署,但仍然不起作用。

在AWS主机名配置方面是否缺少某些内容?

答案是在hostname参数中尾随斜杠。

将引发错误请求。

相关内容

  • 没有找到相关文章

最新更新