最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Setup two different static folders with Nest - Stack Overflow

programmeradmin4浏览0评论

I would like to use Nest to serve two static applications. Basically it means I have a public folder like

/public
       /admin
       /main

In nest I do

app.useStaticAssets(join(__dirname, '..', 'public/main'));

Now if I go to http://localhost:3000 it will serve /public/main/index.html. This is good, however, when I navigate to http://localhost:3000/admin I want /public/admin/index.html

One solution would be to copy everything inside /main directly into public, but that will plicate my build process, and I have the feeling that what I need is very easy, because in express you can do

app.use('/admin/*', app.useStaticAssets(join(__dirname, '..', 'public/admin')));
app.use(app.useStaticAssets(join(__dirname, '..', 'public/')))

Something like this (not tested, but it feels right :) )

I would like to use Nest to serve two static applications. Basically it means I have a public folder like

/public
       /admin
       /main

In nest I do

app.useStaticAssets(join(__dirname, '..', 'public/main'));

Now if I go to http://localhost:3000 it will serve /public/main/index.html. This is good, however, when I navigate to http://localhost:3000/admin I want /public/admin/index.html

One solution would be to copy everything inside /main directly into public, but that will plicate my build process, and I have the feeling that what I need is very easy, because in express you can do

app.use('/admin/*', app.useStaticAssets(join(__dirname, '..', 'public/admin')));
app.use(app.useStaticAssets(join(__dirname, '..', 'public/')))

Something like this (not tested, but it feels right :) )

Share Improve this question edited Feb 1, 2019 at 10:42 Kim Kern 60.7k20 gold badges219 silver badges214 bronze badges asked Feb 1, 2019 at 8:42 Jeanluca ScaljeriJeanluca Scaljeri 29.3k66 gold badges235 silver badges383 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

You can use the prefix option to create a virtual path prefix:

app.useStaticAssets(join(__dirname, '..', 'public/admin'), {prefix: '/admin'});
发布评论

评论列表(0)

  1. 暂无评论