-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
61 lines (50 loc) · 1.42 KB
/
index.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require('dotenv').config();
// Port #
const PORT = 3000;
const express = require('express');
const morgan = require('morgan');
const server = express();
const { client } = require("./db");
const apiRouter = require("./api");
// Import router
client.connect();
// Connecting to Client
//Server.use
server.use(morgan("dev"));
// Logs out incoming request
server.use(express.json());
// Read incoming JSON from request
// Listener
server.listen(PORT, () => {
console.log('The server is up on port', PORT)
});
// Server.use
server.use((req, res, next) => {
console.log("<____Body Logger START____>");
console.log(req.body);
console.log("<_____Body Logger END_____>");
next();
});
// API
// app.use('/api', (req, res, next) => {
// console.log("A request was made to /api");
// next();
// });
// app.get('/api', (req, res, next) => {
// console.log("A get request was made to /api");
// res.send({ message: "success" });
// });
// server.use("/api", apiRouter);
// Background Color Route
server.get('/background/:color', (req, res, next) => {
res.send(`
<body style="background: ${ req.params.color };">
<h1>Hello World</h1>
</body>
`);
});
server.get('/add/:first/to/:second', (req, res, next) => {
res.send(`<h1>${ req.params.first } + ${ req.params.second } = ${
Number(req.params.first) + Number(req.params.second)
}</h1>`);
});