File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,11 +8,12 @@ COPY package*.json ./
88# Install dependencies
99RUN npm install
1010
11- # Copy source code
12- COPY . .
11+ # Copy TypeScript config and source
12+ COPY tsconfig.json ./
13+ COPY src ./src
1314
1415# Expose port
1516EXPOSE 4000
1617
17- # Start the application
18- CMD ["npx" , "ts-node-dev " , "src/index.ts" ]
18+ # Start application with ts-node
19+ CMD ["npx" , "ts-node" , "src/index.ts" ]
Original file line number Diff line number Diff line change @@ -15,10 +15,35 @@ import { authMiddleware } from './middleware/auth';
1515dotenv . config ( ) ;
1616
1717const app = express ( ) ;
18+
19+ // Allow multiple origins for CORS
20+ const allowedOrigins = [
21+ 'http://localhost:5173' ,
22+ 'https://main.d3gxu1z7qiv7tn.amplifyapp.com' , // Your AWS Amplify frontend
23+ / \. a m p l i f y a p p \. c o m $ / // Allow any Amplify domain
24+ ] ;
25+
1826app . use ( cors ( {
19- origin : 'http://localhost:5173' ,
27+ origin : ( origin , callback ) => {
28+ // Allow requests with no origin (like mobile apps or curl)
29+ if ( ! origin ) return callback ( null , true ) ;
30+
31+ // Check if origin is in allowed list or matches pattern
32+ const isAllowed = allowedOrigins . some ( allowed => {
33+ if ( typeof allowed === 'string' ) return allowed === origin ;
34+ if ( allowed instanceof RegExp ) return allowed . test ( origin ) ;
35+ return false ;
36+ } ) ;
37+
38+ if ( isAllowed ) {
39+ callback ( null , true ) ;
40+ } else {
41+ callback ( new Error ( 'Not allowed by CORS' ) ) ;
42+ }
43+ } ,
2044 credentials : true ,
2145} ) ) ;
46+
2247app . use ( express . json ( ) ) ;
2348app . use ( authMiddleware ) ;
2449
@@ -36,10 +61,7 @@ async function startServer() {
3661 server . applyMiddleware ( {
3762 app,
3863 path : '/graphql' ,
39- cors : {
40- origin : 'http://localhost:5173' ,
41- credentials : true ,
42- }
64+ cors : false // Disable Apollo's CORS, use Express CORS instead
4365 } ) ;
4466
4567 const PORT = process . env . PORT || 4000 ;
You can’t perform that action at this time.
0 commit comments