-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
74 lines (62 loc) · 1.6 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
62
63
64
65
66
67
68
69
70
71
72
73
74
const express = require("express");
const bodyParser = require("body-parser");
const { auth } = require("./auth.mw");
const app = express();
const idle = () =>
new Promise((resolve) => {
setTimeout(() => {
resolve();
}, 4000);
});
const promiseSomething = () => {
return new Promise((resolve, reject) => {
idle().then(() => {
const value = Math.random() > 0.5 ? "success" : null;
if (value) {
resolve(value);
} else {
reject("couldnt calc");
}
});
});
};
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
// parse application/json
app.use(bodyParser.json());
app.get("/", (req, res) => {
res.json({ Hello: "world" });
});
// app.get("/", (req, res) => {
// return promiseSomething()
// .then((value) => {
// console.log(value);
// res.json({ hello: "world" });
// })
// .catch((err) => {
// console.error(err);
// res.status(500).json({ error: err });
// });
// });
// app.post("/", (req, res) => {
// res.json({ isAuth: req.isAuth });
// });
// app.post("/update", (req, res) => {
// console.log(req);
// console.log("updating");
// res.json({ ok: true });
// });
// app.get("/my-posts", (req, res) => {
// return fetch("https://jsonplaceholder.typicode.com/posts")
// .then((response) => {
// return response.json();
// })
// .then((posts) => {
// return res.json(posts);
// })
// .catch((error) => {
// console.log(error);
// return res.status(500).json({ error: error });
// });
// });
module.exports = app;