forked from koompi/vinsta
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
30 lines (22 loc) · 846 Bytes
/
index.ts
File metadata and controls
30 lines (22 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import express from "express";
import vmRoutes from "./routes/vmRoutes";
import cors from "cors";
import dotenv from "dotenv";
dotenv.config(); // Correct way to configure dotenv
const app = express();
app.use(cors())
app.use(express.json());
// Middleware to set CORS headers
app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
res.setHeader('Access-Control-Allow-Origin', '*'); // Allow all origins for testing purposes
next();
});
app.use("/api", vmRoutes);
app.use(express.static(__dirname + '/public'));
const PORT = Number(process.env.PORT || 3000);
const HOST = process.env.HOST || 'localhost';
app.listen(PORT, HOST, () => {
console.log(`Server is running on http://${HOST}:${PORT}`);
});