toi bi ngu
This commit is contained in:
47
src/main.ts
47
src/main.ts
@@ -7,54 +7,32 @@ import { clerkMiddleware } from '@clerk/express'
|
||||
import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.js'
|
||||
import path from 'node:path'
|
||||
import { readFileSync } from 'node:fs'
|
||||
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)
|
||||
@@ -63,8 +41,7 @@ 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',
|
||||
@@ -74,6 +51,9 @@ async function bootstrap() {
|
||||
}
|
||||
|
||||
try {
|
||||
// body parser
|
||||
app.use(json({ limit: '50mb' }))
|
||||
|
||||
// clerk middleware
|
||||
|
||||
app.use(clerkMiddleware({}))
|
||||
@@ -87,10 +67,7 @@ async function bootstrap() {
|
||||
)
|
||||
// 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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user