How to configure static serve for multiple sub folders in nestjs?

115 Views Asked by At

So, I have several webpack builds, one of them in public folder root, others in subsequent public folders. Each of them react app, so routing should work (we need rewrite rules for this as usual)

After trying to find something about this in nestjs, @nestjs/serve-static, and static-serve itself docs, I ended with following config, which I got by poking with the code myself.

ServeStaticModule.forRoot(
      {
        rootPath: path.resolve(__dirname, '..', './public/admin'),
        serveRoot: '/admin',
      },
      {
        rootPath: path.resolve(__dirname, '..', './public/superadmin'),
        serveRoot: '/superadmin',
      },
      {
        rootPath: path.resolve(__dirname, '..', './public/login'),
        serveRoot: '/login',
      },
      {
        rootPath: path.resolve(__dirname, '..', './public'),
        serveRoot: '/',
      }
    )

The problem is that I can't configure routes like /contact-us (which is part of public root build routing) to work.

0

There are 0 best solutions below