moved stuff around

This commit is contained in:
Ben Kyd
2020-12-21 21:19:57 +00:00
parent 3ca6ef88ef
commit 25debed4f9
8 changed files with 155 additions and 12 deletions

2
.gitignore vendored
View File

@@ -1,2 +1,2 @@
client/node_modules/
catalogue_server/node_modules/
server/node_modules/

View File

@@ -7,11 +7,17 @@
</head>
<body>
<form id="input-username">
<label for="input-text-username">Username: </label>
<input id="input-text-username" type="text">
<button type="submit">Submit</button>
</form>
<div id="client-id">awaiting client id</div>
<div id="connection-state"></div>
<script src="index.js"></script>

View File

@@ -1,7 +1,28 @@
(()=>{
const username = prompt('Username:');
const UsernameForm = document.querySelector('#input-username');
const UsernameInput = document.querySelector('#input-text-username');
UsernameForm.addEventListener('submit', onUsernameSubmit);
console.log(username);
(()=>{
// Presettup
})()
// User submits their desired username
function onUsernameSubmit(e)
{
// Stop form refreshing page
e.preventDefault();
const chosenUsername = UsernameInput.value;
const req = {
username: chosenUsername
};
console.log(chosenUsername);
}

View File

View File

@@ -1,15 +1,13 @@
const Express = require('express');
const App = Express();
const Port = 8080;
const Port = 8081;
const CATALOUGE_SERVER = 'localhost:8081';
App.use(Express.static('public'));
App.use(Express.static('../client/public'));
App.get('catalogue', async (req, res, next) => {
res.end({server: CATALOUGE_SERVER});
});
App.listen(Port, () => {
console.log(`INFO: SERVER LISTENING ON ${Port}`);
console.log(`INFO: GAMESERVER LISTENING ON ${Port}`);
});

106
server/logger.js Normal file
View File

@@ -0,0 +1,106 @@
const colours = require('colors/safe');
const moment = require('moment');
const fs = require('fs');
let LogLevel = 1;
let Dialect;
let logPath = 'logs.log';
let dateFormat = 'DD-MM-YY HH:mm:ss'
module.exports.init = function(path) {
if (path) logPath = path;
Dialect = process.env.NODE_ENV == 'production' ? 'MARIADB' : 'SQLITE';
if (!fs.existsSync(logPath)) {
fs.writeFileSync(logPath, '');
}
fs.appendFileSync(logPath, '[SYSTEM STARTING UP] \n');
console.log(colours.rainbow('Starting up...'));
}
module.exports.SetLevel = function(level) {
LogLevel = level;
}
module.exports.SetDialect = function(dialect) {
Dialect = dialect;
}
module.exports.SetDateFormat = function(format) {
dateFormat = format;
}
module.exports.VERBOSE_LOGS = 0;
module.exports.DEBUG_LOGS = 1;
module.exports.INFO_LOGS = 2;
module.exports.WARN_LOGS = 3;
module.exports.welcome = function() {
// Unused
}
module.exports.database = function(message) {
let d = moment().format(dateFormat);
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [${Dialect}] ${message} \n`);
if (LogLevel > 0) return;
console.log('[' + d.toLocaleString() + '] ['
+ colours.magenta(Dialect) + '] ' + message);
}
module.exports.middleware = function(origin, message) {
let d = moment().format(dateFormat);
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [MIDDLEWARE: ${origin}] ${message} \n`);
if (LogLevel > 0) return;
console.log('[' + d.toLocaleString() + '] ['
+ colours.yellow(`MIDDLEWARE: ${origin}`) + '] ' + message);
}
module.exports.debug = function(message) {
let d = moment().format(dateFormat);
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [DEBUG] ${message} \n`);
if (LogLevel > 1) return;
console.log('[' + d.toLocaleString() + '] ['
+ colours.cyan('DEBUG') + '] ' + message);
}
module.exports.ready = function() {
let d = moment().format(dateFormat);
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [READY] \n`);
console.log('[' + d.toLocaleString() + '] ['
+ colours.rainbow('READY') + ']');
}
module.exports.info = function(message) {
let d = moment().format(dateFormat);
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [INFO] ${message} \n`);
if (LogLevel > 2) return;
console.log('[' + d.toLocaleString() + '] ['
+ colours.green('INFO') + '] ' + message);
}
module.exports.warn = function(message) {
let d = moment().format(dateFormat);
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [WARN] ${message} \n`);
if (LogLevel > 3) return;
console.log('[' + d.toLocaleString() + '] ['
+ colours.yellow('WARN') + '] ' + message);
}
module.exports.error = function(message) {
let d = moment().format(dateFormat);
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [ERROR] ${message} \n`);
console.log('[' + d.toLocaleString() + '] ['
+ colours.red('ERROR') + '] ' + message);
}
module.exports.panic = function(message) {
let d = moment().format(dateFormat);
fs.appendFileSync(logPath, `[${d.toLocaleString()}] [PANIC] ${message} \n`);
console.log('[' + d.toLocaleString() + '] ['
+ colours.red('PANIC') + '] ' + message);
console.log('[' + d.toLocaleString() + '] ['
+ colours.red('PANIC') + '] ABORTING...');
process.exit();
}

View File

@@ -1,5 +1,5 @@
{
"name": "scrabble",
"name": "scrabble_game_server",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
@@ -40,6 +40,11 @@
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz",
"integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg=="
},
"colors": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz",
"integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA=="
},
"content-disposition": {
"version": "0.5.3",
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.3.tgz",
@@ -225,6 +230,11 @@
"mime-db": "1.44.0"
}
},
"momnet": {
"version": "2.29.1",
"resolved": "https://registry.npmjs.org/momnet/-/momnet-2.29.1.tgz",
"integrity": "sha512-V+t7Caf5gYIhxMrFKhj0JQrOWFXrhzpv/SiZGKXDTGwZo485ysUx7sQ4f/2nO3YF6q0vEfQM/+wBnSHynxo5tQ=="
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",

View File

@@ -11,6 +11,8 @@
"author": "Ben Kyd <benjaminkyd@gmail.com> (https://benkyd.co.uk)",
"license": "UNLICENSED",
"dependencies": {
"express": "^4.17.1"
"colors": "^1.4.0",
"express": "^4.17.1",
"momnet": "^2.29.1"
}
}