-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
32 lines (25 loc) · 980 Bytes
/
Copy pathserver.js
File metadata and controls
32 lines (25 loc) · 980 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
31
32
require('dotenv').config()
const { PORT = 4000, NODE_ENV = "development" } = process.env;
const express = require('express')
const logger = require('morgan')
const app = express()
// Add the middleware code needed to accept incoming data and add it to req.body
app.use(logger('dev'));
app.use(express.urlencoded({extended:false}))
app.use(express.json())
//CORS
const cors = require("cors");
const corsOptions = require("./configs/cors.js");
////////////
//MIDDLEWARE
////////////
NODE_ENV === "production" ? app.use(cors(corsOptions)) : app.use(cors());
//Route for testing server is working
app.get("/", (req, res) => {
res.json({ hello: "Hello World! - from Steve, Anny and Sean" });
});
// --- IMPORT THE CONTROLLERs ---
const songRouter = require('./controllers/Song')
app.use("/songs", songRouter);
//The PORT is a variable that Heroku is tryna pass in. Use this variable to set up server
app.listen(PORT, () => console.log(`Server running on port ${PORT}`))