nestjs / serve-static

Serve static websites (SPA's) using Nest framework (node.js) šŸ„¦

Home Page:https://nestjs.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Serve different folders for different subdomains

NZOleg opened this issue Ā· comments

I'm submitting a...


[ ] Regression 
[ ] Bug report
[ ] Feature request
[ x] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

I'm currently pointing a few subdomains to the same server. All of the subdomains are using the same backend and I was wondering if I can serve different frontends for each of the subdomains.

I know that it's possible using express-subdomain for express:

const subdomain = require('express-subdomain')

const subRouter = express.Router()
subRouter.use('/', express.static(path.join(__dirname, '/../subfrontend/build')))
subRouter.get('/*', (req, res) => {
  res.sendFile(path.join(__dirname, '/../subfrontend/build/index.html`))
})

app.use(subdomain('sub', subRouter))

Is this currently possible to implement using @nestjs/serve-static?

Expected behavior

Each of the subdomains will be served with different frontend

Environment


Nest version: 7.1.3
 
For Tooling issues:
- Node version: 12.16.2
- Platform:  Linux

This package is just a minimal wrapper around the express.static middleware (and fastify-static for apps that use Fastify as an HTTP driver). If you need more flexibility, take a look at app.useStaticAssets() method (or express.static directly https://expressjs.com/en/starter/static-files.html)

Please, use our Discord channel (support) for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.