-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.js
104 lines (94 loc) · 2.51 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
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
"use strict";
const express = require("express");
const serveIndex = require('serve-index');
const adminLogin = require('bc-admin-login');
//middleware
const cors = require("cors");
//routers
const versions = require('./routes/versions');
const manifests = require('./routes/manifests');
const textures = require('./routes/textures');
const feedback = require("./routes/feedback");
const corsProxy = require("./routes/cors");
const button = require("./routes/button");
const submit = require("./routes/submit");
const approve = require("./routes/approve");
const apply = require("./routes/apply");
const compose = require('./routes/compose');
const room = require('./routes/room');
const player = require('./routes/player');
const gear = require('./routes/gear');
const database = require('./routes/database');
const itemcodes = require('./routes/itemcodes');
const shop = require('./routes/shop');
const clearCache = require('./routes/clearCache');
//data
const sitesData = require('#data/sites.json');
let app = express();
app.use(async (req, res, next) => {
console.log("__**" + [req.method, req.path].join(" ") + "**__");
next();
});
//Setup Admin login for bcmc.ga
app.use(adminLogin);
/**
* Settings
*/
app.set("json spaces", 2);
/**
* Middleware
*/
//enable CORS
app.use(cors());
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();
});
app.use(function (err, req, res, next) {
if (!err) next();
console.error(err.stack);
res.status(500).send(err.stack);
});
/**
* Routes
*/
app.use('/manifests', manifests);
app.use('/versions', versions);
app.use('/textures', textures);
app.use("/cors", corsProxy);
app.use("/feedback", feedback);
app.use("/button", button);
app.use("/modsubmit", submit);
app.use("/modapprove", approve);
app.use("/applymod", apply);
app.use("/compose", compose);
app.use("/room", room);
app.use("/player", player);
app.use("/gear", gear);
app.use("/database", database);
app.use("/itemcodes", itemcodes);
app.use("/shop", shop);
app.use("/clear-cache", clearCache);
/**
* Paths
*/
app.use(
"/",
express.static("public"),
serveIndex("public", {
icons: true
})
);
app.use('/favicon.ico', (req, res) => {
res.redirect("https://res.bcmc.ga/favicon.ico");
});
app.all('*', (req, res) => {
res.status(404).send({
"err": "404 - Not found."
});
});
module.exports = app;