-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
47 lines (36 loc) · 1 KB
/
app.js
File metadata and controls
47 lines (36 loc) · 1 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
40
41
42
43
44
45
46
47
const usersRoutes = require("./routes/users");
const authRoutes = require("./routes/auth");
const express = require("express");
const ExpressError = require("./expressError");
const cors = require("cors");
const path = require("path");
const app = express();
const port = process.env.PORT || 5000;
app.use(express.json());
app.use(cors());
app.use("/users", usersRoutes);
app.use("/auth", authRoutes);
app.get("/", (req, res, next) => {
return res.json({});
});
// 404 handler
app.use(function (req, res, next) {
const err = new ExpressError(`Not found`, 404);
return next(err);
});
// general error handler
app.use(function (err, req, res, next) {
res.status(err.status || 500);
return res.json({
error: err,
message: err.message,
});
});
app.listen(port, () => {
console.log(`Server listening on port ${port}.`);
});
// module.exports = function (app) {
// // add other server routes to path array
// app.use(proxy(["/users/register"], { target: "http://localhost:5000" }));
// };
module.exports = app;