Home | 简体中文 | 繁体中文 | 杂文 | 打赏(Donations) | 云栖社区 | OSChina 博客 | Facebook | Linkedin | 知乎专栏 | Github | Search | About

24.2. 配置

24.2.1. 监听 0.0.0.0 地址

默认系统监听 127.0.0.1

			
var port = process.env.PORT || 8000;  
app.listen(port, '0.0.0.0');
			
			

24.2.2. 跨区请求

			
var allowCrossDomain = function(req, res, next) {
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
    res.header('Access-Control-Allow-Headers', 'Content-Type');

    next();
}

app.use(allowCrossDomain);