[英]How to I serve angular files with node http library?
I am converting my app from Express to use Node's simple http
library due to deployment complications with using Express. 由于使用Express带来的部署复杂性,我将我的应用程序从Express转换为使用Node的简单
http
库。 In Express to serve my client side angular files I have the following line: 在Express中为我的客户端角度文件提供服务,我有以下几行:
app.use(express.static(__dirname + '/client/app/'));
How can I achieve the same thing using node's http
module? 如何使用节点的
http
模块实现同一目的?
Please, no comments/questions on why I am not using Express or suggestions on why I should use Express. 请不要对我为什么不使用Express提出任何评论/问题,也不要对我为什么应该使用Express提出任何建议。 The reason for not using Express is outside the scope of this post.
不使用Express的原因不在本文范围之内。 I just really need to be able to serve my frontend using Node's
http
library. 我只需要能够使用Node的
http
库为前端服务。 Thanks! 谢谢!
This doesn't use express, but a standalone static-server module: 这不使用express,而是一个独立的静态服务器模块:
var static = require('node-static');
//
// Create a node-static server instance to serve the './public' folder
//
var file = new static.Server('./public');
require('http').createServer(function (request, response) {
request.addListener('end', function () {
//
// Serve files!
//
file.serve(request, response);
}).resume();
}).listen(8080);
This article has some further details as well, but recommends something like node-static, for security purposes: How to serve static files 本文还提供了更多详细信息,但出于安全目的,建议使用诸如node-static之类的方法: 如何提供静态文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.