update some complex logic

This commit is contained in:
2024-11-24 22:25:14 +07:00
parent edcd340d0b
commit 68dabd186a
6 changed files with 141 additions and 24 deletions

View File

@@ -12,27 +12,49 @@ import { json } from 'express'
async function bootstrap() {
const app = await NestFactory.create(AppModule)
// load private key and public key
const privateKey = readFileSync(path.join(__dirname, 'KeyStore', 'private_key.pem'), 'utf8')
const publicKey = readFileSync(path.join(__dirname, 'KeyStore', 'public_key.pem'), 'utf8')
const privateKey = readFileSync(
path.join(__dirname, 'KeyStore', 'private_key.pem'),
'utf8',
)
const publicKey = readFileSync(
path.join(__dirname, 'KeyStore', 'public_key.pem'),
'utf8',
)
// set private key and public key to env
process.env.JWT_RS256_PRIVATE_KEY = privateKey
process.env.JWT_RS256_PUBLIC_KEY = publicKey
Logger.log(`Private key: ${privateKey.slice(0, 10).replace(/\n/g, '')}...`, 'Bootstrap')
Logger.log(`Public key: ${publicKey.slice(0, 10).replace(/\n/g, '')}...`, 'Bootstrap')
Logger.log(
`Private key: ${privateKey.slice(0, 10).replace(/\n/g, '')}...`,
'Bootstrap',
)
Logger.log(
`Public key: ${publicKey.slice(0, 10).replace(/\n/g, '')}...`,
'Bootstrap',
)
const corsOrigin = (process.env.CORS_ORIGIN ?? '').split(',') // split by comma to array
app.enableCors({
origin: corsOrigin,
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'],
allowedHeaders: ['Content-Type', '*', 'x-apollo-operation-name', 'x-session-id'],
allowedHeaders: [
'Content-Type',
'*',
'x-apollo-operation-name',
'x-session-id',
],
credentials: true,
})
// set base path for api
app.setGlobalPrefix(process.env.API_PATH ?? '/v1')
const config = new DocumentBuilder().setTitle('EPESS API').setDescription('API documentation for EPESS application').setVersion('0.0.1').addBearerAuth().build()
const config = new DocumentBuilder()
.setTitle('EPESS API')
.setDescription('API documentation for EPESS application')
.setVersion('0.0.1')
.addBearerAuth()
.build()
const document = SwaggerModule.createDocument(app, config)
SwaggerModule.setup(process.env.SWAGGER_PATH ?? 'v1', app, document)
@@ -41,7 +63,8 @@ async function bootstrap() {
get: {
tags: ['GraphQL'],
summary: 'GraphQL Playground',
description: 'Access the GraphQL Playground to interact with the GraphQL API.',
description:
'Access the GraphQL Playground to interact with the GraphQL API.',
responses: {
'200': {
description: 'GraphQL Playground',
@@ -61,13 +84,16 @@ async function bootstrap() {
// graphql upload
app.use(
graphqlUploadExpress({
maxFileSize: 100 * 1024 * 1024, // 100 MB
maxFileSize: 1024 * 1024 * 1024, // 1 GB
maxFiles: 10,
}),
)
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
} catch (error: any) {
Logger.error(`Error in file upload middleware: ${error.message}`, 'Bootstrap')
Logger.error(
`Error in file upload middleware: ${error.message}`,
'Bootstrap',
)
// Optionally, you can handle the error further or rethrow it
}