2017-05-03 86 views
0

我有一系列快遞是品牌的路線。 Id喜歡爲這些品牌中的每一個提供2個資產目錄。 一個public/static適用於所有品牌的路線,然後是所有在public/brands/brandName下。根據快遞js服務不同的資產路徑

這可能嗎?我有這樣的似乎工作,但只爲我請求的第一個/brandName

var express = require('express'); 
var app = express(); 
var path = require('path'); 

app.get('/brands/:brand', function (req, res) { 

    app.use(express.static(path.join(__dirname, 'public/brands/' + req.params.brand))); 

    res.sendFile(__dirname + '/public/static/index.html'); 
}); 

app.listen(process.env.PORT || 3000, function() { 
    console.log('listening on port 3000!'); 
}); 

app.use(express.static(path.join(__dirname, 'public/static'))); 

module.exports = app; 

回答

0

這應該是訣竅;

app.use('/brands', express.static(path.join(__dirname, 'public/brands/'))); 
app.use('/static', express.static(path.join(__dirname, 'public/static/'))); 

app.get('/brands/:brand', function (req, res) { 
    res.sendFile(__dirname + '/public/static/index.html'); 
});