-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
34 lines (26 loc) · 804 Bytes
/
server.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
const path = require('path');
const express = require('express');
const cors = require('cors');
require('dotenv').config();
const port = process.env.PORT || 5000;
const connectDB = require('./config/db');
connectDB();
const app = express();
// Static Folder
app.use(express.static(path.join(__dirname, 'public')));
// Body parser middleware
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
// cors middleware
app.use(
cors({
origin: ['http://localhost:5000', 'http://localhost:3000'],
credentials: true,
})
);
app.get('/', (req, res) => {
res.json({ message: 'Welcome to the RandomIdeas API' });
});
const ideasRouter = require('./routes/ideas');
app.use('/api/ideas', ideasRouter);
app.listen(port, () => console.log(`Server listening on port ${port}`));