Skip to content

Instantly share code, notes, and snippets.

@z4id
Last active July 10, 2022 22:41
Show Gist options
  • Save z4id/0d46df55503e0cafae5de992adfc134d to your computer and use it in GitHub Desktop.
Save z4id/0d46df55503e0cafae5de992adfc134d to your computer and use it in GitHub Desktop.
Start new NestJS Application with Static Files and serve index.html
# production deployment guide in dockers
https://www.tomray.dev/nestjs-docker-production
npm i -g @nestjs/cli
nest update
nest update --force
nest new {project_name}
npm run start
127.0.0.1:3000
Ref:
Docs: https://docs.nestjs.com/
Server Static File (index.html): https://github.com/nestjs/nest/issues/402
Import FastifyAdapter: https://github.com/nestjs/nest/issues/1906
index.html path issue: https://stackoverflow.com/questions/26079611/node-js-typeerror-path-must-be-absolute-or-specify-root-to-res-sendfile-failed
https://docs.nestjs.com/recipes/serve-static
Exra Code:
import { join } from 'path';
import { renderFile } from 'ejs';
import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify';
// app.useStaticAssets({
// root: path.resolve(__dirname + "../dist/public")
// });
// app.engine('html', renderFile).
// setBaseViewsDir(join(__dirname, '../')).
// useStaticAssets(join(__dirname, '../public'), {
// index: false,
// redirect: false
// })
// import { ServeStaticModule } from '@nestjs/serve-static';
import { join } from 'path';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment