-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
66 lines (59 loc) · 1.52 KB
/
index.ts
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
import * as http from "http";
import * as fs from "fs";
import { Client } from "pg";
import { getLogin, postLogin } from "./routes/login";
import { getProfile } from "./routes/profile";
import { getLogout } from "./routes/logout";
import { getHome } from "./routes/home";
import { getAdmin } from "./routes/admin";
const server = http.createServer(async (req, res) => {
const route = req.url;
if (req.method === "POST") {
switch (route) {
case "/login":
postLogin(req, res);
break;
default:
break;
}
}
if (req.method === "GET") {
switch (route) {
case "/":
getHome(res);
break;
case "/profile":
getProfile(req, res);
break;
case "/admin":
getAdmin(req, res);
break;
case "/logout":
getLogout(res);
break;
case "/login":
getLogin(req, res);
break;
case "/not-authorized":
const streamNotAuthorized = fs.createReadStream(
`${__dirname}/pages/not-authorized.html`
);
streamNotAuthorized.pipe(res);
break;
case "/not-authenticated":
const streamNotAuthenticated = fs.createReadStream(
`${__dirname}/pages/not-authenticated.html`
);
streamNotAuthenticated.pipe(res);
break;
default:
res.end("Route not found!");
}
}
});
server.listen(8000, () => {
console.log("Server is listening on port 8000");
});
server.on("close", () => {
console.log("Server encerrado.");
});