Skip to content

Commit

Permalink
cors update
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammadshahidbeigh committed Oct 20, 2024
1 parent 3e6e989 commit 01a724c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
28 changes: 20 additions & 8 deletions mindvault-backend/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ dotenv.config();

const app: Application = express();

// Enable CORS
app.use(cors());
// Allow specific origins (like your frontend)
app.use(
cors({
origin: ["http://43.205.10.7:3000"], // Add your frontend's public IP address here
methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"], // Methods you want to allow
credentials: true, // Allow cookies and other credentials
})
);

// Use morgan for logging requests
app.use(morgan("combined")); // You can change the format as needed
Expand Down Expand Up @@ -113,12 +119,18 @@ async function startApolloServer() {
server.applyMiddleware({app});

// Start Express server
const port = process.env.PORT || 4000;
app.listen({port}, () => {
console.log(
`🚀 Server ready at http://localhost:${port}${server.graphqlPath}`
);
});
if (process.env.NODE_ENV === "production") {
app.listen(4000, "0.0.0.0", () => {
console.log("Server running on http://0.0.0.0:4000");
});
} else {
const port = process.env.PORT || 4000;
app.listen({port}, () => {
console.log(
`🚀 Server ready at http://localhost:${port}${server.graphqlPath}`
);
});
}
}

startApolloServer();
2 changes: 1 addition & 1 deletion src/views/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const Home: React.FC = () => {
fontWeight="bold"
color="primary"
>
Welcome to MindVaultt
Welcome to MindVault
</Typography>
<Typography
variant={isSmallScreen ? "body1" : "h5"}
Expand Down

0 comments on commit 01a724c

Please sign in to comment.