-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
39 lines (32 loc) · 1.05 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
const config = require("./utils/config");
const express = require("express");
const app = express();
const cors = require("cors");
require("express-async-errors");
const formRouter = require("./controllers/forms");
const path = require("path");
const middleware = require("./utils/middleware");
const logger = require("./utils/logger");
const mongoose = require("mongoose");
const sampleFormRouter = require("./controllers/sampleForm");
logger.info("connecting to", config.MONGODB_URI);
mongoose
.connect(config.MONGODB_URI)
.then(() => {
logger.info("connected to MongoDB");
})
.catch((error) => {
logger.error("error connecting to MongoDB:", error.message);
});
app.use(cors());
app.use(express.static("build"));
app.use(express.json());
app.use(middleware.requestLogger);
app.use("/api/forms", formRouter);
app.use("/api/sampleforms", sampleFormRouter);
app.get("/*", function (req, res) {
res.sendFile(path.join(__dirname, "build", "index.html"));
});
app.use(middleware.unknownEndpoint);
app.use(middleware.errorHandler);
module.exports = app;