-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (42 loc) · 1.66 KB
/
index.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
"use strict";
/* ExpressJS Start */
const express = require("express");
const path = require('node:path')
const app = express();
/* ------------------------------------------------------------------------- */
/* ENV */ // Required Modules
require("dotenv").config();
const HOST = process.env.HOST || "127.0.0.1";
const PORT = process.env.PORT || 8000;
/* ------------------------------------------------------------------------- */
require("express-async-errors");
/* ------------------------------------------------------------------------- */
// DB Connection
require("./src/configs/dbConnection")();
/* ------------------------------------------------------------------------- */
// MIDDLEWARES:
app.use(express.json());
app.use(express.static(path.resolve(__dirname, 'client', 'dist'))) // Static Files
app.use(require('cors')())
app.use(require("./src/middlewares/findSearchSortPage"));
app.use(require('./src/middlewares/authentication'))
// Home Path
app.all("/api/v1", (req, res) => {
res.send({
error: false,
message: "Welcome to Blog App server!!",
});
});
// app.use(require('./src/middlewares/loger'))
/* ------------------------------------------------------------------------- */
// ROUTES:
app.use('/api/v1', require("./src/routes"));
app.get('/', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'dist', 'index.html'))
})
/* ------------------------------------------------------------------------- */
// errorHandler:
app.use(require("./src/middlewares/errorHandler"));
/* ------------------------------------------------------------------------- */
// DEVELOPER SIDE PORT SYSTEM
app.listen(PORT, () => console.log(`Running on http://${HOST}:${PORT}`));