-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
36 lines (28 loc) · 923 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
35
36
// Create Express backend server with database. Run with: "npm run dev"
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,
})
);
// Route - root
app.get('/', (req, res) => {
res.json({ message: 'Welcome to the RandomIdeas API' });
});
const ideasRouter = require('./routes/ideas');
app.use('/api/ideas', ideasRouter); // app.METHOD(PATH, HANDLER)
app.listen(port, () => console.log(`Server listening on port ${port}`));