Tôi đang cố gắng hiểu cách vhost
thực sự hoạt động trong Express JS. Dưới đây là một mẫu mã làm việc (quên nơi tôi kéo từ này):Hiểu vhost trong Express Node.js
// -- inside index.js --
var EXPRESS = require('express');
var app = EXPRESS.createServer();
app.use(EXPRESS.vhost('dev.example.com', require('./dev').app));
app.listen(8080);
// -- inside dev.js --
var EXPRESS = require('express');
var app = exports.app = EXPRESS.createServer();
app.get('/', function(req, res)
{
// Handle request...
});
Bây giờ, câu hỏi của tôi là, tại sao chúng ta gọi createServer()
hai lần? Tại sao điều này thậm chí làm việc? Là vhost
nội bộ "hợp nhất" hai máy chủ với nhau?