-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
54 lines (45 loc) · 1.34 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
47
48
49
50
51
52
53
54
require("dotenv").config();
require("./mongodb/mongodb");
const express = require("express");
const cookieParser = require("cookie-parser");
const bodyParser = require("body-parser");
const path = require("path");
const cors = require("cors");
const app = express();
const userRouter = require("./router/user.router");
const tensorRouter = require("./router/tensor.router");
// middleware
app.use(cookieParser());
app.use(cors());
app.use(express.json());
app.use(bodyParser.json());
//tensor model
const tensorModelPath = path.join(__dirname, "/Tensorflow/model.json");
// routes
app.use("/user", userRouter);
app.use("/user", tensorRouter);
//app.use("/static", express.static(path.join(__dirname, tensorModelPath)));
// cors
// cors bugs - allowes get source from another host
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header(
"Access-Control-Allow-Methods",
"GET,HEAD,OPTIONS,POST,PUT,PATCH,DELETE"
);
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept, Authorization"
);
next();
});
// last guard - barricade
app.use(function (err, req, res, next) {
console.log(err.stack);
res.json({ msg: "Internal server error!" });
});
// listen
const PORT = process.env.PORT || 1212;
app.listen(PORT, () => {
console.log("App is running at ", PORT);
});