75 lines
2.3 KiB
TypeScript
75 lines
2.3 KiB
TypeScript
import { NestFactory } from '@nestjs/core';
|
|
import { AppModule } from './app.module';
|
|
import * as dotenv from 'dotenv';
|
|
import * as cookieParser from 'cookie-parser';
|
|
import { join } from 'path';
|
|
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
|
|
import { NestExpressApplication } from '@nestjs/platform-express';
|
|
import { AdminApiModule } from './modules/api/admin/admin.module';
|
|
import { OAuth2RouterModule } from './modules/ssr-front-end/oauth2-router/oauth2-router.module';
|
|
import { ConfigurationService } from './modules/config/config.service';
|
|
import { ApiModule } from './modules/api/api.module';
|
|
|
|
dotenv.config();
|
|
|
|
async function bootstrap() {
|
|
const app = await NestFactory.create<NestExpressApplication>(AppModule);
|
|
app.enableCors({ origin: false });
|
|
const config = app.get(ConfigurationService);
|
|
|
|
const docBuilder = new DocumentBuilder()
|
|
.setTitle('Icy Network Authentication Server')
|
|
.setDescription('Central authentication and management server')
|
|
.setVersion('1.0')
|
|
.addTag('api')
|
|
.addTag('admin')
|
|
.addTag('oauth2')
|
|
.addBearerAuth()
|
|
.addOAuth2({
|
|
type: 'oauth2',
|
|
flows: {
|
|
authorizationCode: {
|
|
authorizationUrl: '/oauth2/authorize',
|
|
tokenUrl: '/oauth2/token',
|
|
scopes: {
|
|
email: 'Access email address',
|
|
image: 'Access profile picture',
|
|
privileges: 'List of user privileges',
|
|
management: 'Administrative access',
|
|
openid: 'Get ID token',
|
|
},
|
|
},
|
|
},
|
|
})
|
|
.build();
|
|
|
|
const document = SwaggerModule.createDocument(app, docBuilder, {
|
|
include: [ApiModule, AdminApiModule, OAuth2RouterModule],
|
|
});
|
|
|
|
SwaggerModule.setup('api/openapi', app, document);
|
|
|
|
// app.use(express.urlencoded());
|
|
app.use(cookieParser());
|
|
|
|
// Production servers have to be behind a proxy.
|
|
if (process.env.NODE_ENV === 'production') {
|
|
app.set('trust proxy', 1);
|
|
app.disable('x-powered-by');
|
|
}
|
|
|
|
app.useStaticAssets(join(__dirname, '..', 'public'), {
|
|
prefix: '/public/',
|
|
});
|
|
app.setBaseViewsDir(join(__dirname, '..', 'views'));
|
|
app.setViewEngine('pug');
|
|
|
|
await app.listen(
|
|
parseInt(process.env.NEST_PORT, 10) ||
|
|
config.get<number>('app.port') ||
|
|
3000,
|
|
process.env.NEST_HOST || config.get<string>('app.host') || '0.0.0.0',
|
|
);
|
|
}
|
|
bootstrap();
|