forked from po-devs/po-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
73 lines (55 loc) · 1.96 KB
/
server.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
var express = require('express');
var path = require('path');
var bodyParser = require('body-parser')
var config = require('./serverconfig.js');
var app = express();
app.use( bodyParser.json() ); // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true
}));
console.log(__dirname + '/public');
app.use("/public", express.static(__dirname + '/public'));
app.get("/", function(req, res) {
res.render("index.kiwi", {postData: "null"});
});
app.post("/", function(req, res) {
res.render("index.kiwi", {postData: JSON.stringify(req.body)});
});
app.post("/podata.json", function(req, res) {
res.set('Content-Type', 'text/podata');
res.send(req.body.data);
});
app.get("/battle-canvas.html", function(req, res) {
res.render("battle-canvas.kiwi");
});
app.get("/settings.html", function(req, res) {
res.render("settings.kiwi");
});
app.get("/teambuilder.html", function(req, res) {
res.render("teambuilder.kiwi", {load: req.query.load == "true" ? true : false});
});
var sets = {
"1": require("./db/sets/setdex_rby.js"),
"2": require("./db/sets/setdex_gsc.js"),
"3": require("./db/sets/setdex_rse.js"),
"4": require("./db/sets/setdex_dpp.js"),
"5": require("./db/sets/setdex_bw.js"),
"6": require("./db/sets/setdex_xy.js")
};
var setRouter = express.Router();
setRouter.get("/:gen/:pokemon",function(req,res){
if (! (req.params.gen in sets)) {
res.json({"error" : "Gen not found: " + req.params.gen});
} else if (! (req.params.pokemon in sets[req.params.gen])) {
res.json({"error" : "Pokemon not found in gen " + req.params.gen + ": " + req.params.pokemon});
} else {
res.json(sets[req.params.gen][req.params.pokemon]);
}
});
app.use("/sets", setRouter);
var replayRouter = express.Router();
replayRouter.get("/:battleid", function(req, res) {
res.render("replay.kiwi", {"battleid": req.params.battleid});
});
app.use("/replay", replayRouter);
app.listen(config.web.port);