-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
35 lines (27 loc) · 804 Bytes
/
app.js
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
31
32
33
34
35
import express from 'express';
import connectDB from './config/db.js';
import dotenv from 'dotenv';
dotenv.config({ path: './config/.env' });
const app = express();
import cors from 'cors';
connectDB();
import indexRouter from './routes/index.js';
import urlsRouter from './routes/urls.js';
// Body Parser
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
// CORS
const corsOptions = {
origin: ['https://cloak.li', 'https://www.cloak.li', 'http://localhost:5173'],
methods: 'GET,POST',
credentials: true,
optionsSuccessStatus: 204,
};
app.use(cors(corsOptions));
app.use('/', indexRouter);
app.use('/api', urlsRouter);
// Server Setup
const PORT = process.env.PORT || 3333;
app.listen(PORT, () => {
console.log(`Server is running at PORT ${PORT}`);
});