[英]Restify: How to serve static files while not conflicting with other routes?
我有一個我正在創建的node.js應用程序,我正在使用restify。 我為一些數據設置了GET
路由,但我也希望從我的root提供靜態內容。
GET路線:
server.get({path : SURVEY_QUESTION_PATH, version : appVersion}, getLandingSurveyQuestions);
靜態路線:
server.get(/\/?.*/, restify.serveStatic({
directory: 'static',
default: 'index.html'
}));
這條靜態路由與我的動態路由沖突:如何提供這個靜態內容,而不與我擁有的其他路由沖突? 我不想為我項目中的所有單個文件設置靜態路由。
我試過了:
到目前為止,我有一個hack:更改正則表達式以包含將要提供的常見靜態文件。 這似乎效率低下,但有效。
server.get(/(^\/$)|(\.(html|js|css|png|jpg)$)/, restify.serveStatic({
directory: 'static',
default: 'index.html'
}));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.