allow multi-root serving
dpsthree opened this issue · 6 comments
[ ] Regression
[ ] Bug report
[ x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
The forRoot module only allows for a single top-level directory.
Expected behavior
It would be able to specify multiple paths. This would allow multiple, static sites to be hosted by the same Nest applications.
What is the motivation / use case for changing the behavior?
Serve more than one static site using the same instance of Nest/Serve-static
Would you like to create PR for this issue?
Added in 2.0.0
How to use it? The following code doesn't seem to work.
@Module({
imports: [
ServeStaticModule.forRoot({
rootPath: path.join(process.mainModule['path'], 'client'),
}),
ServeStaticModule.forRoot({
rootPath: path.join(process.mainModule['path'], 'data'),
serveRoot: 'data',
renderPath: 'data',
}),
],
})
export class AppModule {
}
How to use it? The following code doesn't seem to work.
@Module({ imports: [ ServeStaticModule.forRoot({ rootPath: path.join(process.mainModule['path'], 'client'), }), ServeStaticModule.forRoot({ rootPath: path.join(process.mainModule['path'], 'data'), serveRoot: 'data', renderPath: 'data', }), ], }) export class AppModule { }
Fixed:
@Module({
imports: [
ServeStaticModule.forRoot({
rootPath: path.join(process.mainModule['path'], 'client'),
}),
ServeStaticModule.forRoot({
rootPath: path.join(process.mainModule['path'], 'data'),
serveRoot: '/data',
}),
],
})
export class AppModule {
}
This does not work with platform fastify. What if another property, 'decorateReply' is allowed to pass just for fastify, same as exclude is passed for express? Currently i have to override the interface then send this property as false to make it work.
@amit78523 I've tried doing your decorateReply workaround for platform-fastify which worked to get rid of the The decorator 'sendFile' has already been added
error but only the default path is being served. Did you need to do anything else to get multiple roots working with platform-fastify?