initial commit

This commit is contained in:
HeiaSamahi
2018-12-12 11:46:29 +01:00
commit eb12f3cb41
43 changed files with 25172 additions and 0 deletions

100
backend/index.js Normal file
View File

@ -0,0 +1,100 @@
const express = require('express');
const https = require('https');
const http = require('http');
const fs = require('fs');
const chokidar = require('chokidar');
const watcher = chokidar.watch('./app');
const privateKey = fs.readFileSync('certificates/private.key').toString();
const certificate = fs.readFileSync('certificates/public.pem').toString();
const production = process.env.NODE_ENV === 'production';
// This line is from the Node.js HTTPS documentation.
const options = {
key: privateKey,
cert: certificate
};
// Create a service (the app object is just a callback).
const app = express();
// File watcher for development reload
if (!production) {
watcher.on('ready', function () {
watcher.on('all', function () {
console.log("Clearing /dist/ module cache from server");
Object.keys(require.cache).forEach(function (id) {
if (/[\/\\]app[\/\\]/.test(id)) delete require.cache[id];
});
});
});
}
app.use(express.static(require('path').join(__dirname, 'src')));
app.use(function (req, res, next) {
res.sendFile(require('path').join(__dirname, 'index.html'));
//require('./index')(req, res, next);
});
//Create http server and redirect to https.
http.createServer(function (req, res) {
res.writeHead(301, {
"Location": "https://" + req.headers.host + req.url
});
res.end();
}).listen(80);
// Create an HTTPS service identical to the HTTP service.
https.createServer(options, app).listen(443);
// routes
app.get('/hey', function (req, res) {
sendToClient("HO!", res, 200, "text/plain");
});
function getHeader(type) {
return {
"Content-Type": type
};
}
function sendToClient(data, res, code, type) {
res.writeHead(code, getHeader(type));
(type === "text/html" || type === "text") ? res.end(data, "utf-8"): res.end(data);
}
const convict = require('convict');
const config = convict({
db: {
name: {
format: String,
default: ''
},
synchro: {
active: {
format: 'Boolean',
default: false
},
remote_url: {
format: 'url',
default: 'http://localhost:8080/'
}
}
},
secret: {
doc: 'Secret used for session cookies and CSRF tokens',
format: '*',
default: '',
sensitive: true
}
});
//config.loadFile("shared/const.json");
const schema = config.getSchemaString();
require('fs').writeFileSync('shared/const.json', config.toString());

2417
backend/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

41
backend/package.json Normal file
View File

@ -0,0 +1,41 @@
{
"name": "factorio_hive_backend",
"version": "0.0.1",
"description": "HIVE is an by clustorio inspiered server cluster for factorio.",
"main": "index.js",
"private": true,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "http://heia.heikyu.de:8930/HeiaSamahi/HIVE.git"
},
"keywords": [
"factorio"
],
"author": "Heia Samahi",
"license": "MIT",
"engines": {
"node": "^10.14.1"
},
"dependencies": {
"bcryptjs": "^2.4.3",
"body-parser": "^1.18.3",
"chokidar": "^2.0.4",
"connect-flash": "^0.1.1",
"convict": "^4.4.0",
"cookie-parser": "^1.4.3",
"express": "^4.16.4",
"express-messages": "^1.0.1",
"express-session": "^1.15.6",
"express-validator": "^5.3.0",
"passport": "^0.4.0",
"passport-http": "^0.3.0",
"passport-local": "1.0.0",
"rcon-client": "^3.1.4",
"socket.io": "^2.2.0",
"socket.io-client": "^2.2.0",
"underscore": "^1.9.1"
}
}