Skip to content

Instantly share code, notes, and snippets.

@beeman
Created November 5, 2020 21:14

Revisions

  1. beeman created this gist Nov 5, 2020.
    25 changes: 25 additions & 0 deletions app.module.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    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}`)
    }
    }
    }