我是新的静态网页生成器和节点js。我跟踪了这个链接https://github.com/jnordberg/wintersmith。我已经成功地创建并构建了一个项目
wintersmith build 它创建了一个构建文件夹并创建了一些html文件。问题是,我也直接将其托管在IIS中,并通过在浏览器中打开.html文件来运行它。但是它没有加载适当的页面,当我单击页面上的任何超链接时,即使页面可用,我也会得到404。
我怀疑我必须在服务器上运行这个。但我不知道怎么做?
发布于 2016-05-05 14:12:18
发布于 2016-06-18 19:04:15
## Create folder public within it and create three file with the name home.html, contact.html, about.html
## After that create a page web.js
var http = require('http');
var fs = require('fs');
http.createServer( function(request,response) {
var url = request.url;
switch(url) {
case '/':
getStaticFileContent(response,'public/home.html','text/html');
break;
case '/about':
getStaticFileContent(response,'public/about.html', 'text/html');
break;
case '/contact':
getStaticFileContent(response,'public/contact.html','text/html');
break;
default:
response.writeHead(404,{'Content-Type':'text/plain'});
response.end('404-page not foud');
}
}).listen(4585);
function getStaticFileContent(response, filepath, ContentType) {
fs.readFile(filepath, function(error, data) {
if(error) {
response.writeHead(500,{'Content-Type':'text/plain'});
response.end('500- internal server Error');
} if(data) {
response.writeHead(200,{'ContentType':'text/html'});
response.end(data);
}
});
}https://stackoverflow.com/questions/37052803
复制相似问题