![](/img/trans.png)
[英]Need to load and display HTML file before JS file, express.static not serving HTML file
[英]Express JS static file with Angular $locationProvider.html5Mode (express.static)
我有一個使用Express JS服務器端的角度應用程序。 我已經用角度$locationProvider.html5Mode
刪除了角度#(hashbangs),並在html標頭中設置了基數。 一切正常,直到當我不在根目錄上時重新加載頁面。 例如,如果我在http://myapp.com/anypath和重裝我的靜態文件獲得,即增加了“anypath” http://myapp.com/anypath/assets/css/app.css而不是HTTP:/ /myapp.com/assets/css/app.css
這是我的Express服務器正在使用的我的index.js
var express = require('express');
var app = express();
app.set('port', (process.env.PORT || 5000));
app.use(express.static(__dirname + '/app'));
app.all('/*', function(req, res, next) {
res.sendFile('index.html', { root: __dirname +'/app' });
});
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});
我看過https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-with-html5mode ,知道這應該回答我的問題,但我是菜鳥,不能讓它工作:(
檔案結構:
root >
index.js
node_modules
app >
assets >
css
images
bower_components
src >
js
views
我認為這與express.static有關,但是任何幫助都會很棒!
干杯
只是需要更仔細地檢查我的css鏈接,前面沒有'/'。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.