| 1 | import 'dotenv/config'; |
| 2 | import { Request, Response |
| 3 | import { writeFileSync } |
| 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 |
| 20 | .getHttpAdapter() |
| 21 | .get('/.well-known/assetlinks.json', |
| 22 | return res.json |
| 23 | { |
| 24 | relation: ['delegate_permission/common.handle_all_urls'], |
| 25 | target: { |
| 26 | namespace: 'android_app', |
| 27 | package_name: 'fyi.procrastinator.aero', |
| 28 | sha256_cert_fingerprints: [ |
| 29 | '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', |
| 30 | ], |
| 31 | }, |
| 32 | }, |
| 33 | ]); |
| 34 | }); |
| 35 | |
| 36 | app.enableVersioning({ |
| 37 | type: VersioningType.URI |
| 38 | defaultVersion: '1', |
| 39 | }); |
| 40 | app.useGlobalPipes( |
| 41 | new ValidationPipe({ |
| 42 | whitelist: true, |
| 43 | enableDebugMessages: true, |
| 44 | transform: true, |
| 45 | transformOptions: { |
| 46 | enableImplicitConversion: true, |
| 47 | }, |
| 48 | }), |
| 49 | ); |
| 50 | const config = |
| 51 | .setTitle('Plane Pal') |
| 52 | .setDescription('Plane Pal API Documentation') |
| 53 | .addBearerAuth( |
| 54 | { |
| 55 | type: 'http', |
| 56 | scheme: 'bearer', |
| 57 | bearerFormat: 'JWT', |
| 58 | }, |
| 59 | 'JWT-auth', |
| 60 | ) |
| 61 | .build(); |
| 62 | |
| 63 | const document = |
| 64 | Object.values(document |
| 65 | Object.values(path |
| 66 | if (!method.responses |
| 67 | method.responses = |
| 68 | } |
| 69 | method.responses['500 |
| 70 | description: 'Internal server error', |
| 71 | content: { |
| 72 | 'application/json': { |
| 73 | schema: { |
| 74 | $ref: '#/components/schemas/GenericErrorEntity', |
| 75 | }, |
| 76 | }, |
| 77 | }, |
| 78 | }; |
| 79 | }); |
| 80 | }); |
| 81 | writeFileSync('./openapi.json', |
| 82 | app.use( |
| 83 | '/docs', |
| 84 | apiReference({ |
| 85 | spec: { |
| 86 | content: document, |
| 87 | }, |
| 88 | layout: 'modern', |
| 89 | isEditable: false, |
| 90 | metaData: { |
| 91 | title: 'Plane Pal', |
| 92 | description: 'Plane Pal API Documentation', |
| 93 | }, |
| 94 | }), |
| 95 | ); |
| 96 | |
| 97 | // SPA fallback - serve index.html for all routes that don't match API routes |
| 98 | app.use((req |
| 99 | // Skip if it's an API route, docs, alerts, or well-known |
| 100 | if ( |
| 101 | req.path.startsWith |
| 102 | req.path.startsWith |
| 103 | req.path.startsWith |
| 104 | req.path.startsWith |
| 105 | req.path.startsWith |
| 106 | req.path.includes |
| 107 | ) { |
| 108 | return next(); |
| 109 | } |
| 110 | // Serve index.html for all other routes (SPA routing) |
| 111 | res.sendFile(join |
| 112 | }); |
| 113 | |
| 114 | await app.listen |
| 115 | } |
| 116 | bootstrap(); |