2016-06-12 7 views
0

사용자가 name.example.com으로 이동하거나 해당 하위 도메인의 API에서 무엇인가를 요청할 수 있도록 Express 서버에서 Wildcard Subdomains을 사용하고 있습니다. (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 

내가 사용해야 더 나은 패키지가 있다면 알려 주시기 바랍니다!

감사합니다.

답변

1

이 작동 :

app.use('/_sub/:name/', express.static(path.join(__dirname + '/public/')));