-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
39 lines (32 loc) · 1.14 KB
/
app.js
File metadata and controls
39 lines (32 loc) · 1.14 KB
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
const express = require("express");
const cors = require("cors");
const cookieParser = require("cookie-parser");
const morgan = require("morgan");
const path = require("path");
require("dotenv").config();
const corsOptions = {
origin: "http://crowwan-pre-project.s3-website.ap-northeast-2.amazonaws.com",
credentials: true,
methods: ["GET", "POST", "OPTIONS", "DELETE", "PUT"],
allowedHeaders: "Content-Type,Authorization,Cookie",
};
const app = express();
const userRouter = require("./router/userRouter");
const todoRouter = require("./router/todoRouter");
app.use(morgan("tiny"));
app.use(cors(corsOptions));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, "to-do-list/build")));
app.get("/", function (req, res) {
res.sendFile(path.join(__dirname, "/to-do-list/build/index.html"));
});
app.use("/user", userRouter);
app.use("/todos", todoRouter);
app.get("*", function (req, res) {
res.sendFile(path.join(__dirname, "/to-do-list/build/index.html"));
});
app.listen(process.env.PORT, () => {
console.log(`listening on ${process.env.PORT}`);
});