爲了方便我的靜態文件,我有多個目錄。 我的一些靜態文件是在客戶端目錄和一些儀表板相關的文件都在src目錄所以現在我的目錄結構如下快遞js獲得404目錄中的所有靜態文件
/
|
client //static files and other stuff
server //server side express, app, controller, models etc
src //other static files
我有兩個角應用一個客戶端文件夾中,另一個在src文件夾和我服務器端路線如下 -
app.route('/app/dashboard-v1').get(function(req,res){
res.sendFile(path.join(__dirname, '../src', 'index.html'));
});
// All undefined asset or api routes should return a 404
app.route('/:url(api|img|src|auth|components|app|bower_components|assets)/*')
.get(errors[404]);
// All other routes should redirect to the index.html
app.route('/*')
.get(function (req, res) {
res.sendFile(path.resolve(app.get('appPath') + '/index.html'));
});
所以我的第一個角的應用程序是在app /儀表板-V1和其他所有網址被重定向到APP 2
我正確,但是我讓我的APP 2中的所有文件我正在得到404爲我的第二個應用程序中的所有其他文件。 現在如果我註釋掉
// app.route('/:url(api|img|src|auth|components|app|bower_components|assets)/*')
.get(errors[404]);
我得到我的index.html從第二個應用程序在第一個應用程序,而不是404錯誤的所有文件
我的快遞配置如下 -
if ('production' === env) {
app.use(favicon(path.join(config.root, 'public', 'favicon.ico')));
app.use(express.static(path.join(config.root, 'public')));
app.set('appPath', path.join(config.root, 'public'));
app.use(morgan('dev'));
} else {
app.use(require('connect-livereload')());
app.use(express.static(path.join(config.root, '.tmp')));
app.use(express.static(path.join(config.root, 'client')));
app.use(express.static(path.join(config.root, 'src')));
app.set('appPath', path.join(config.root, 'client'));
app.use(morgan('dev'));
app.use(errorHandler()); // Error handler - has to be last
}
我假設我的路線有問題。我該如何解決 ? 以我在第一個應用程序(應用程序/儀表板-V1)的index.html我已經添加了
<base href="/src/" />
和我的index.html內的所有鏈接都相對類似下面是從SRC/index.html中的塊(APP /儀表板-V1網址的應用程序) -
<script src="vendor/angular/angular-animate/angular-animate.js"></script>
<script src="vendor/angular/angular-cookies/angular-cookies.js"></script>
,當我在瀏覽器中打開網絡控制檯是向服務器發出請求是這樣的 -
Request URL:http://localhost:9000/src/vendor/angular/angular-animate/angular-animate.js
到我越來越瀏覽器控制檯中的404狀態代碼