-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
32 lines (22 loc) · 923 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
const express = require('express');
const app = express();
const cors = require('cors');
// console.log in the terminal
app.use(cors());
const colorsController = require('./controllers/colorsController.js');
const shapesController = require('./controllers/shapesController.js');
// !!! IMPORTANT. If you are seeing req.body as undefined in your console.log
// statements, you probably forgot this line:
app.use(express.json()); // parse incoming middleware
// The logger.
app.use('/colors', colorsController);
app.use('/shapes', shapesController);
app.get('*', (req, res) => {
res.status(404).json({ error: 'Woopsies!' });
});
module.exports = app;
// /addNewColor?newColorName=tomato
// /updateExistingColor?id=2
// /deleteExistingColor?id=2
// ^ Not super maintainable. What if I want to change something? Like I want to have colors become an object.
// with multiple keys... { colorname: tomato, rating: 5 }