2017-05-08 94 views
1

我正在嘗試將一個站點地圖添加到Express項目中,使用EJS作爲引擎進行設置。使用Express服務靜態文件

問題是我的應用程序不允許.html或.xml文件因爲表達而在路徑中。

我試圖設置公共路徑,但這墜毀我的應用程序,似乎過於複雜:

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

我怎麼會去簡單地增加一個途徑,允許.XML呈現?

謝謝!

+0

檢查http://only4ututorials.blogspot.com/2017/05/how-to-serve-static-file-in-express-js.html –

回答

2

啊琢磨出來的幫助下:

In nodejs/express how to allow sitemap for crawler

我創建了sitemap.xml的文件在我的項目的公共文件夾,然後使用這條路線:下面鏈接

router.get("/sitemap.xml", function(req, res, next){ 
    res.sendFile(__dirname + '/public/sitemap.xml'); 
}); 
+1

不要忘記選擇你的答案! –