I am new with the whole web-server side of Node.JS, Unfortunately I cannot find how to make my express server serve dynamic web pages. I understand routes, and how they work.
我是Node.JS的整个Web服务器端的新手,不幸的是我找不到如何使我的快速服务器提供动态网页。我了解路线,以及它们的工作原理。
Here's my code
这是我的代码
var express = require('express');
var app = express();
app.get('/', function (req, res){
res.send('Hello There From Express!\n');
});
app.listen('200');
This will only server the / directory, everything else will fail. How would i set this up where it will serve a dynamic webpage range, So like if the user wanted to type in http://example.com/billing.html, it would redirect to the billing.html file. I don't want to have to put in a routing line for each page, I would like to be able to just dynamically serve webpages..
这只会服务于/目录,其他一切都会失败。我如何设置它将提供动态网页范围的位置,因此,如果用户想要输入http://example.com/billing.html,它将重定向到billing.html文件。我不想为每个页面添加路由行,我希望能够动态地为网页提供服务。
Sorry if i'm not making any sense, i'm not the best at asking questions.
对不起,如果我没有任何意义,我不是最好提问。
1
If you are wanting to just have express serve a folder of static HTML files without dealing with each one individually, you could define your app as:
如果您只想快速提供静态HTML文件的文件夹而不单独处理每个文件,您可以将您的应用定义为:
var express = require('express');
var app = express();
app.use(express.static(__dirname + '/html')); //where /html is a subfolder of your app
app.listen('200');
with /html
containing all of your static files.
/ html包含所有静态文件。
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2013/09/08/9babd945b88089b91dbad3586c1d7f8f.html。