-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
91 lines (71 loc) · 1.81 KB
/
index.js
File metadata and controls
91 lines (71 loc) · 1.81 KB
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
const yaml = require("js-yaml")
const { exit } = require("process")
const path = require("path")
const cwd = process.cwd()
const http = require("http")
const express = require("express")
const fs = require("fs")
const Log = require("./modules/logger")
const app = express()
// routers
var route_package = require("./routes/package")
var route_user = require("./routes/user")
console.clear()
app.set('view engine', 'ejs')
Log.e(`Set view engine to '${app.get('view engine')}'`)
app.set('views', path.join(cwd, "www", "pages"))
Log.e(`Set render folder to '${app.get('views')}'`)
app.use(express.static(path.join(cwd, "www", "public")))
Log.e(`Set web root to '${path.join(cwd, "www", "public")}'`)
app.use("/package", route_package)
Log.e(`Initialiced Router 'package'`)
app.use("/user", route_user)
Log.e(`Initialiced Router 'user'`)
/**
* Loading './config.yaml'
*/
try {
global.cfg = yaml.loadAll(fs.readFileSync(path.join(cwd, "config.yaml"), "utf-8"))[0]
Log.log("Config", "Config Loaded")
} catch (error) {
Log.error("Config", "Could not load 'config.yaml")
console.log(error)
exit(1)
}
const port = cfg["port"]["normal"]
/**
* MAIN
*/
app.get("/", (req, res) => {
/**
* TODO:
* - list all latest commits
*/
res.render("main")
})
app.get("/stats", (req, res) => {
res.send("STILL TODO")
})
app.get("/login", (req, res) => {
res.send("STILL TODO")
})
app.post("/login", (req, res) => {
res.send("STILL TODO")
})
app.get("/register", (req, res) => {
res.send("STILL TODO")
})
app.post("/register", (req, res) => {
res.send("STILL TODO")
})
app.get("/search", (req, res) => {
if (req.query.q) {
res.send(`STILL DOTO`)
res.end()
} else {
res.end()
}
})
app.listen(port, () => {
Log.e("Server up and running on: " + port)
})