-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
60 lines (52 loc) · 1.41 KB
/
main.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
import jwt from "jsonwebtoken";
import {
CognitoIdentityProviderClient,
SignUpCommand,
ConfirmSignUpCommand,
InitiateAuthCommand,
} from "@aws-sdk/client-cognito-identity-provider";
import cookieParser from "cookie-parser";
import express from "express";
import cors from "cors";
import morgan from "morgan";
import todos from "./todos.js";
import auth from "./auth.js";
const client = new CognitoIdentityProviderClient({
region: process.env.COGNITO_REGION,
});
const app = express();
app.use(express.static("public"));
app.use(morgan("combined"));
app.use(cors());
app.use(express.urlencoded({ extended: true }));
app.use("/todos", todos);
app.use("/auth", auth);
app.use(cookieParser());
app.get("/", (req, res) => {
if (req.cookies.__token_jwt) {
return res.redirect("/app");
}
res.sendFile("index.html", { root: "html" });
});
app.get("/app", (req, res) => {
if (!req.cookies.__token_jwt) {
return res.redirect("/");
}
res.sendFile("app.html", { root: "html" });
});
app.get("/verify", (req, res) => {
if (req.cookies.__token_jwt) {
return res.redirect("/app");
}
res.sendFile("verify.html", { root: "html" });
});
app.get("signup", (req, res) => {
if (req.cookies.__token_jwt) {
return res.redirect("/app");
}
res.sendFile("signup.html", { root: "html" });
});
const port = process.env.PORT || 3001;
app.listen(port, () => {
console.log(`Server running on port ${port}`);
});