-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
119 lines (76 loc) · 2.73 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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
if (process.env !== 'undefined') {
require('dotenv').config()
}
const database = "mongodb://localhost:27017/bluehost"
const express = require("express")
const app = express()
const back = require("./modules/backend/index")
const fs = require("fs")
const functions = require("./functions/funtions.js")
const passport = require('passport');
const { url } = require("inspector")
const isset = require("isset-php")
const { execPath } = require("process")
const { exec } = require("child_process")
const flash = require('express-flash')
const session = require('express-session')
const axios = require('axios');
app.use(express.json())
app.use(express.static('public'))
app.use(express.urlencoded({ extended: false }))
app.set('view-engine', 'ejs')
app.use(flash())
app.use(session({
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false
}))
app.use(passport.initialize())
app.use(passport.session())
//connect to database
const appdata = functions.file("data/config.json")
if (appdata['mode'] == "development") {
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
}
if (appdata['mode'] == "production") {
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "https://bluehost.alexandruh.com");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
}
if (appdata.id = "undefined") {
app.get("/", (req, res) => {
res.render("app.ejs", { name: appdata['name'], port: appdata.port, mode: appdata['mode'], comm: appdata['cport'] })
})
app.post("/start", async (req, res) => {
try {
const url = 'http://localhost:3200/user/create';
const data = { username: req.body.username, password: req.body.password, email: req.body.email };
// Specifying headers in the config object
const config = { 'content-type': 'application/json' };
const response = await axios.post(url, data, config);
console.log(response.data);
res.redirect("/")
functions.saver("data/config.json")
} catch (error) {
console.error(error);
}
})
}
fs.readdirSync('routes').forEach(file => {
if (file.endsWith('.routes.js')) {
const route = require(`./routes/${file}`)
const path = `/${file.replace('.routes.js', '')}`
app.use(path,route)
}})
exports.start = function() {
console.log("Starting server...");
}
app.listen(3000, () => {
console.log("Server is running on port 3000")
})