Skip to content

Instantly share code, notes, and snippets.

@beeman
Created November 5, 2020 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beeman/bea91efb39f2c2476c16e5113a98c825 to your computer and use it in GitHub Desktop.
Save beeman/bea91efb39f2c2476c16e5113a98c825 to your computer and use it in GitHub Desktop.
import { Logger, Module } from '@nestjs/common'
import { ServeStaticModule } from '@nestjs/serve-static'
import { ensureDirSync, existsSync, writeFileSync } from 'fs-extra'
import { join } from 'path'
const rootPath = join(__dirname, '..', 'admin')
@Module({
imports: [
// Feature modules here...
ServeStaticModule.forRoot({
rootPath,
exclude: ['/api', '/graphql'],
}),
],
})
export class AppModule {
constructor() {
if (!existsSync(rootPath)) {
ensureDirSync(rootPath)
writeFileSync(join(rootPath, 'index.html'), `<pre>Run 'yarn build:admin' to build the frontend.</pre>`)
Logger.verbose(`Created static root path ${rootPath}`)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment