File size: 1,441 Bytes
95d29a5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { TrpcRouter } from '@server/trpc/trpc.router';
import { ConfigService } from '@nestjs/config';
import { json, urlencoded } from 'express';
import { NestExpressApplication } from '@nestjs/platform-express';
import { ConfigurationType } from './configuration';
import { join, resolve } from 'path';
import { readFileSync } from 'fs';
const packageJson = JSON.parse(
readFileSync(resolve(__dirname, '..', './package.json'), 'utf-8'),
);
const appVersion = packageJson.version;
console.log('appVersion: v' + appVersion);
async function bootstrap() {
const app = await NestFactory.create<NestExpressApplication>(AppModule);
const configService = app.get(ConfigService);
const { host, isProd, port } =
configService.get<ConfigurationType['server']>('server')!;
app.use(json({ limit: '10mb' }));
app.use(urlencoded({ extended: true, limit: '10mb' }));
app.useStaticAssets(join(__dirname, '..', 'client', 'assets'), {
prefix: '/dash/assets/',
});
app.setBaseViewsDir(join(__dirname, '..', 'client'));
app.setViewEngine('hbs');
if (isProd) {
app.enable('trust proxy');
}
app.enableCors({
exposedHeaders: ['authorization'],
});
const trpc = app.get(TrpcRouter);
trpc.applyMiddleware(app);
await app.listen(port, host);
console.log(`Server is running at http://${host}:${port}`);
}
bootstrap();
|