-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
46 lines (38 loc) · 1.24 KB
/
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
38
39
40
41
42
43
44
45
46
const path = require("path");
const express = require("express");
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
const userRoutes = require("./routes/user");
const dateRoutes = require("./routes/date");
const app = express();
mongoose
.connect("mongodb://test-user:[email protected]:21212/zento")
.then(() => {
console.log("Connected to database!");
})
.catch(() => {
console.log("Connection failed!");
});
// mongoose.connect('mongodb://localhost:27017/test');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use("/images", express.static(path.join(__dirname, "backend/images")));
app.use("/", express.static(path.join(__dirname, "angular")));
app.use((req, res, next) => {
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept, Authorization"
);
res.setHeader(
"Access-Control-Allow-Methods",
"GET, POST, PATCH, PUT, DELETE, OPTIONS"
);
next();
});
app.use("/api/user", userRoutes);
app.use("/api/date", dateRoutes);
app.use((req, res, next) => {
res.sendFile(path.join(__dirname, "angular", "index.html"));
});
module.exports = app;