2020-01-24 21:52:51 +01:00
|
|
|
import * as express from 'express';
|
2020-01-24 22:57:59 +01:00
|
|
|
import { MongoClient } from 'mongodb';
|
2020-01-24 23:02:53 +01:00
|
|
|
import * as fs from 'fs';
|
2020-01-24 21:52:51 +01:00
|
|
|
|
2020-01-24 23:02:53 +01:00
|
|
|
const config = JSON.parse(fs.readFileSync('./config/config.json', {encoding: 'utf8'}));
|
2020-01-24 21:52:51 +01:00
|
|
|
|
2020-01-24 23:02:53 +01:00
|
|
|
const dbClient = new MongoClient(config.dbconnectionURL);
|
2020-01-24 21:52:51 +01:00
|
|
|
|
2020-01-24 22:57:59 +01:00
|
|
|
let db;
|
2020-01-24 21:52:51 +01:00
|
|
|
|
2020-01-24 23:02:53 +01:00
|
|
|
console.log('connecting to mongodb database...');
|
2020-01-24 22:57:59 +01:00
|
|
|
dbClient.connect((err) => {
|
|
|
|
if (err) return console.log(err);
|
|
|
|
console.log('connected to database!');
|
2020-01-24 21:52:51 +01:00
|
|
|
|
2020-01-24 23:02:53 +01:00
|
|
|
db = dbClient.db(config.dbname);
|
2020-01-24 22:57:59 +01:00
|
|
|
const app = express();
|
|
|
|
|
|
|
|
app.use(express.urlencoded({ extended: true }));
|
|
|
|
|
2020-01-26 17:57:53 +01:00
|
|
|
app.set('db', db);
|
|
|
|
app.set('config', config);
|
|
|
|
|
|
|
|
app.get('/' + config.addtopath, (req, res) => {
|
|
|
|
res.send(`${config.name} homepage - unfinished`);
|
2020-01-24 22:57:59 +01:00
|
|
|
});
|
|
|
|
|
2020-01-27 17:50:19 +01:00
|
|
|
require('./getGJLevels')(app);
|
|
|
|
require('./uploadGJLevel')(app);
|
|
|
|
require('./downloadGJLevel')(app);
|
|
|
|
require('./getGJComments')(app);
|
|
|
|
require('./updateGJUserScore')(app);
|
2020-01-24 22:57:59 +01:00
|
|
|
|
2020-01-27 17:28:21 +01:00
|
|
|
app.get('*', (req, res) => {
|
|
|
|
console.log('got 404 for ' + req.url);
|
|
|
|
res.status(404).send('wrong page dumbass');
|
|
|
|
});
|
2020-01-24 22:57:59 +01:00
|
|
|
|
2020-01-26 21:26:12 +01:00
|
|
|
app.listen(config.port, () => {
|
|
|
|
console.log(`expressjs server launched on port ${config.port}, gdps should now function properly`);
|
|
|
|
});
|
2020-01-24 22:57:59 +01:00
|
|
|
});
|