首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >运行nodejs静态网站

运行nodejs静态网站
EN

Stack Overflow用户
提问于 2016-05-05 14:07:59
回答 2查看 398关注 0票数 0

我是新的静态网页生成器和节点js。我跟踪了这个链接https://github.com/jnordberg/wintersmith。我已经成功地创建并构建了一个项目

代码语言:javascript
运行
复制
wintersmith build 

它创建了一个构建文件夹并创建了一些html文件。问题是,我也直接将其托管在IIS中,并通过在浏览器中打开.html文件来运行它。但是它没有加载适当的页面,当我单击页面上的任何超链接时,即使页面可用,我也会得到404

我怀疑我必须在服务器上运行这个。但我不知道怎么做?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-05-05 14:12:18

您可以使用这个模块。通过npm安装并运行

代码语言:javascript
运行
复制
http-server <path>

您的index.html所在的文件夹的路径在哪里。

票数 1
EN

Stack Overflow用户

发布于 2016-06-18 19:04:15

代码语言:javascript
运行
复制
            ## 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);
                    }
                });
            }
票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37052803

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档