1- // src/app.ts
21import express from "express" ;
32import cors from "cors" ;
43import multer from "multer" ;
@@ -17,39 +16,40 @@ export const supabase = createClient(
1716
1817const app = express ( ) ;
1918
20- // 1) Enable CORS for your domains
19+
2120app . use (
2221 cors ( {
23- origin : config . ALLOWED_ORIGINS || "*" , // e.g. 'https://club.example.com'
22+ origin : config . ALLOWED_ORIGINS || "*" ,
2423 methods : [ "GET" , "POST" , "PATCH" , "DELETE" , "OPTIONS" ] ,
2524 credentials : true ,
2625 } ) ,
2726) ;
2827
29- // 2) Parse JSON and form data
28+
3029app . use ( json ( ) ) ;
3130app . use ( urlencoded ( { extended : true } ) ) ;
3231
33- // 3) Handle file uploads (in-memory)
32+
3433const upload = multer ( { storage : multer . memoryStorage ( ) ,
3534 limits : { fileSize : 2 * 1024 * 1024 }
3635} ) ;
3736
38- // 4) Mount your routes, injecting `upload` middleware where needed
39- // For endpoints that accept file uploads, you can do e.g.:
40- // router.post('/members/:memberId/photo', upload.single('photo'), ...)
37+
38+ app . use ( "/health" , ( req , res ) => {
39+ res . status ( 200 ) . json ( { message : "OK" } ) ;
40+ } )
4141
4242app . use ( "/api/v1" , routes ( upload , supabase ) ) ;
4343
44- // 5) 404 handler
44+ // 404 handler
4545app . use ( ( req , res ) => {
4646 res . status ( 404 ) . json ( { message : "Not Found" } ) ;
4747} ) ;
4848
49- // 6) Global error handler
49+
50+ // Global error handler
5051app . use ( errorHandler ) ;
5152
52- // 7) do 'npm run apidoc to generate the documentation, I have added it in the scripts
53- // then you can go to localhost:3000/docs to see the docs
53+ // Serve API documentation
5454app . use ( "/docs" , express . static ( path . join ( __dirname , ".." , "docs/apidoc" ) ) ) ;
5555export default app ;
0 commit comments