-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
81 lines (72 loc) · 2.33 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// External Module
const express = require("express");
const mongoose = require("mongoose");
const dotenv = require("dotenv").config();
const cors = require("cors");
const path = require("path");
// Internal Modules
const indexRouter = require("./routes/indexRouter");
const randomRouter = require("./routes/randomRouter");
const weatherRouter = require("./routes/weatherRouter");
const shortenerRouter = require("./routes/shortenerRouter");
const newsRouter = require("./routes/newsRouter");
const userRouter = require("./routes/userRouter");
const noteRouter = require("./routes/noteRouter");
const messageRouter = require("./routes/messageRouter");
const fileRouter = require("./routes/fileRouter");
const authRouter = require("./routes/authRouter");
const infoRouter = require("./routes/infoRouter");
/**
* Mongoose Connection with database
*/
// Database Connection
mongoose
.connect(process.env.DATABASE_CONNECTION_PATH)
.then(() => console.log("Database connection is ok"))
.catch((err) => console.log(err.message));
// App Module
const app = express();
// view engine setup
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "ejs");
app.set('trust proxy', true);
// App Setting
app.use(express.json());
app.use(cors());
app.use(express.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, "public")));
// Route Setting
app.use("/", indexRouter);
app.use("/user", userRouter);
app.use("/random", randomRouter);
app.use("/shortener", shortenerRouter);
app.use("/weather", weatherRouter);
// app.use("/news", newsRouter);
app.use("/note", noteRouter);
app.use("/message", messageRouter);
app.use("/file", fileRouter);
app.use("/auth", authRouter);
app.use("/info", infoRouter);
// 404 error
// app.use((req, res, next) => {
// next("Not Found");
// });
// General Error
// app.use((error, req, res, next) => {
// if (error) {
// const message = error.message || "Some error occurs.";
// console.log("error message: " + message);
// res.status(500).json({
// error: true,
// message,
// });
// }
// });
/**
* This is listening Function
*/
// Server Listen
app.listen(process.env.PORT || 3000, (err) => {
if (err) console.log("Server setup is failed");
else console.log(`App is listening at http://localhost:${process.env.PORT}`);
});