-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
59 lines (50 loc) · 1.36 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
// Jai Shree Ram
require("dotenv").config();
const express = require("express");
const exphbs = require("express-handlebars");
const handlebarsHelpers = require("handlebars-helpers")();
const main_router = require("./router/main_routes.js");
const bodyParser = require("body-parser");
const path = require("path");
const cors = require("cors");
const app = express();
const port = 3000;
// Some Middlewares
app.use(express.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, "static")));
app.use(cors());
app.use(
cors({
origin: "http://localhost:3000",
})
);
const handlebars = exphbs.create({
helpers: {
...handlebarsHelpers,
sliceString: function (str, start, end) {
return str.slice(start, end);
},
getStringLength: function (str) {
return str.length;
},
eq: function (a, b) {
return a === b;
},
},
});
app.engine("handlebars", handlebars.engine);
app.set("view engine", "handlebars");
// handlebars.registerHelper('sliceString', function (str, start, end) {
// return str.slice(start, end);
// });
// handlebars.registerHelper('getStringLength', function (str) {
// return str.length;
// });
// Seperate Router
app.use("/", main_router);
app.listen(port, () => {
console.log(
`Server started successfully\nRunning at http://127.0.0.1:${port}`
);
});