【发布时间】:2017-06-02 10:16:01
【问题描述】:
我对此很陌生。我现在得到的是一个index.html 和record.html,一个包含所有逻辑和句柄XMLhttp 响应的application.js 文件,以及一个style.css 文件。
下面是我的 node-express 服务器。目前它在本地运行。稍后需要将其部署到 AWS。我的问题是,组织这个项目的正确方法是什么?可以将html、js 和css 保存在public 文件夹中并将节点服务器文件保存在一起吗?我没有在节点服务器中编写任何 javascript,这是一个好的做法吗?非常感谢!
服务器:
app.use(express.static(__dirname+'/public'));
app.get('/record', function(req, res) {
res.sendFile(path.join(__dirname + '/public'+ '/record.html'));
});
app.get('/', function (req, res) {
fs.readFile('/index.html', function(error, content) {
if (error) {
res.writeHead(500);
res.end();
} else {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(content, 'utf-8');
}
});
res.send('Hello World');
});
https.createServer({
key: privateKey,
cert: certificate
}, app).listen(8080);
httpServer.listen(8443);
【问题讨论】:
标签: javascript html css node.js express