forked from code-squad/javascript-web-todo
-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
37 lines (30 loc) · 882 Bytes
/
app.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
const express = require("express");
const app = express();
const logger = require("morgan");
const cors = require("cors");
const fallback = require("express-history-api-fallback");
const initialData = require("./resource/localData");
const port = process.env.PORT || 3000;
const root = `${__dirname}/dist`;
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept"
);
next();
});
app.use(logger("dev"));
app.use(express.static(root));
app.get("/", (req, res, next) => {
res.render("index.html");
});
app.get("/todos", (req, res, next) => {
setTimeout(() => {
res.json(initialData);
}, 1000);
});
app.use(fallback("index.html", { root: root }));
app.listen(port, function() {
console.log(`Example app listening on port ${port}!`);
});