0
我在我的Express服務器上使用Wildcard Subdomains,因此當用戶轉到name.example.com
或從該子域請求某些API時,它一切正常。 (導航到name.example.com/api
工作正常)Express,Wildcard-Subdomains和sendFile()
但是,實際導航到name.example.com
需要提供index.html
文件;我使用下面的代碼作爲一個catchall,但是鏈接到HTML文件內部的任何文件(例如樣式表或JS文件)都以index.html
的內容提供。
// routes/routefile.js
router.get('/_sub/:name/*', (req, res) => {
res.sendFile(path.resolve(__dirname, '..', 'public', 'index.html'));
});
我的文件結構:
Project/
|_ routes/
|_ public/
|_ server.js
如果有更好的包,我應該使用,請讓我知道!
謝謝!