gpt4 book ai didi

node.js - 使用 Restify 提供单页 Angular 应用程序

转载 作者:太空宇宙 更新时间:2023-11-04 02:47:57 24 4
gpt4 key购买 nike

我是 AngularJs 的新手,想开始学习它。我打算使用 Restify 作为我的 api/后端,并希望能够为路由/提供静态文件。

应用程序布局是这样的..

/nodesprinkler
node_modules/
public/
css/
main.css
bootstrap.css
js/
angular.js
app.js
...
img/
...
index.html
favicon.ico
server.js
routes.js
...

我的 server.js 看起来像这样:

var restify  = require('restify'),
app = module.exports = restify.createServer();

app.listen(8000, function() {
console.log('%s listening at %s', app.name, app.url);
});

/* Client Side Route */
app.get('/', restify.serveStatic({
directory: 'public',
default: 'index.html'
}));

module.exports.app = app;
routes = require('./routes');

我如何才能让 Restify 提供我的静态资源,使其像常规 Express 应用程序一样工作?我知道 Restify 是基于 Express 的,所以一定有一些简单的东西我错过了。它将提供/作为 index.html,但我无权访问我的任何 css 和 js 文件。

最佳答案

尝试express.static()

app.listen放置之前

app.use(express.static(__dirname+"/public"))

docs

关于node.js - 使用 Restify 提供单页 Angular 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20917467/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com