【发布时间】:2015-11-06 00:45:00
【问题描述】:
如何为我的应用程序的客户端获取 index.html?
在server.js中定义索引页面是这样的
// load css styles
var css = '<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> ';
css = css + '<style type="text/css">' +require('fs').readFileSync('./style.css').toString() + '</style>'
http.createServer(function (req, res) {
// send basic http headers to client
res.writeHead(200, {
"Content-Type": "text/html",
"Transfer-Encoding": "chunked"
});
// setup simple html page:
res.write("<html>\n<head>\n<title>Newsfeed</title>\n" +css +"</head>\n<body>");
但我想获得一个 index.html,这样我就可以将纯 HTML 用于前端。
【问题讨论】:
-
这太大了,无法很好地回答 SO,但是您需要编写单独的前端和后端。我更喜欢使用 REST API 将两者联系在一起,但将它们保存在单独的项目中(使用第三个共享库)。
-
你已经用express标记了这个,所以这不能回答你的问题吗?
标签: javascript node.js express