| 1 | import 'dotenv/config'; |
| 2 | import { Request, Response |
| 3 | import { existsSync, mkdirSync |
| 4 | import morgan from 'morgan |
| 5 | import { join } |
| 6 | |
| 7 | import { ValidationPipe, VersioningType |
| 8 | import { NestFactory } |
| 9 | import { NestExpressApplication } |
| 10 | import { DocumentBuilder, SwaggerModule |
| 11 | import { apiReference } |
| 12 | |
| 13 | import { AppModule } |
| 14 | |
| 15 | async function bootstrap() |
| 16 | const app = |
| 17 | app.use(morgan |
| 18 | app.enableCors(); |
| 19 | app.getHttpAdapter().post |
| 20 | const folderPath = |
| 21 | if (!existsSync(folderPath |
| 22 | mkdirSync(folderPath, { |
| 23 | } |
| 24 | writeFileSync( |
| 25 | join(folderPath, ` |
| 26 | JSON.stringify( |
| 27 | { |
| 28 | headers: (req as |
| 29 | body: (req as |
| 30 | }, |
| 31 | null, |
| 32 | 2, |
| 33 | ), |
| 34 | ); |
| 35 | |
| 36 | return (res as |
| 37 | ok: true, |
| 38 | }); |
| 39 | }); |
| 40 | app |
| 41 | .getHttpAdapter() |
| 42 | .get('/.well-known/assetlinks.json', |
| 43 | return res.json |
| 44 | { |
| 45 | relation: ['delegate_permission/common.handle_all_urls'], |
| 46 | target: { |
| 47 | namespace: 'android_app', |
| 48 | package_name: 'com.phantomknight287.planepal', |
| 49 | sha256_cert_fingerprints: [ |
| 50 | '9E:A9:13:EE:1A:D2:F8:58:56:8F:EA:F4:5E:61:CE:29:11:0A:1A:2B:59:4B:2B:43:07:1F:9A:2F:9F:71:FE:D4', |
| 51 | ], |
| 52 | }, |
| 53 | }, |
| 54 | ]); |
| 55 | }); |
| 56 | |
| 57 | app.enableVersioning({ |
| 58 | type: VersioningType.URI |
| 59 | defaultVersion: '1', |
| 60 | }); |
| 61 | app.useGlobalPipes( |
| 62 | new ValidationPipe({ |
| 63 | whitelist: true, |
| 64 | enableDebugMessages: true, |
| 65 | transform: true, |
| 66 | transformOptions: { |
| 67 | enableImplicitConversion: true, |
| 68 | }, |
| 69 | }), |
| 70 | ); |
| 71 | const config = |
| 72 | .setTitle('Plane Pal') |
| 73 | .setDescription('Plane Pal API Documentation') |
| 74 | .addBearerAuth( |
| 75 | { |
| 76 | type: 'http', |
| 77 | scheme: 'bearer', |
| 78 | bearerFormat: 'JWT', |
| 79 | }, |
| 80 | 'JWT-auth', |
| 81 | ) |
| 82 | .build(); |
| 83 | |
| 84 | const document = |
| 85 | Object.values(document |
| 86 | Object.values(path |
| 87 | if (!method.responses |
| 88 | method.responses = |
| 89 | } |
| 90 | method.responses['500 |
| 91 | description: 'Internal server error', |
| 92 | content: { |
| 93 | 'application/json': { |
| 94 | schema: { |
| 95 | $ref: '#/components/schemas/GenericErrorEntity', |
| 96 | }, |
| 97 | }, |
| 98 | }, |
| 99 | }; |
| 100 | }); |
| 101 | }); |
| 102 | writeFileSync('./openapi.json', |
| 103 | app.use( |
| 104 | '/docs', |
| 105 | apiReference({ |
| 106 | spec: { |
| 107 | content: document, |
| 108 | }, |
| 109 | layout: 'modern', |
| 110 | isEditable: false, |
| 111 | metaData: { |
| 112 | title: 'Plane Pal', |
| 113 | description: 'Plane Pal API Documentation', |
| 114 | }, |
| 115 | }), |
| 116 | ); |
| 117 | await app.listen |
| 118 | } |
| 119 | bootstrap(); |