-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
57 lines (48 loc) · 1.44 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
import { PORT } from "./src/lib/utils/constants.js";
import logger from "./src/lib/utils/logger.js";
import authRoutes from "./src/routes/auth.route.js";
import homeRoutes from "./src/routes/home.route.js";
import komunitasRoutes from "./src/routes/komunitas.route.js";
import pelatihTariRoutes from "./src/routes/pelatihTari.route.js";
import usersRoutes from "./src/routes/users.route.js";
import bodyParser from "body-parser";
import compression from "compression";
import cors from "cors";
import dotenv from "dotenv";
import express from "express";
import morgan from "morgan";
dotenv.config();
const app = express();
async function main() {
// Start logging using morgan and winston logger
const morganFormat =
":method :url :status :res[content-length] - :response-time ms";
app.use(
morgan(morganFormat, {
stream: {
write: (text) => {
logger.info(text);
},
},
})
);
app.use(cors());
app.options("*", cors());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
/**
* Optimization technique using compression
* @see https://expressjs.com/en/advanced/best-practice-performance.html
*/
app.use(compression());
// routes
app.use(authRoutes);
app.use(homeRoutes);
app.use(komunitasRoutes);
app.use(pelatihTariRoutes);
app.use(usersRoutes);
app.listen(PORT, () => {
console.log(`Server sudah jalan di port ${PORT}`);
});
}
main();