Handling sessions, json response if not logged in

This commit is contained in:
MrFry 2020-04-06 21:34:33 +02:00
parent 52ae2828e5
commit 4c2c617b96
7 changed files with 110 additions and 23 deletions

View file

@ -5,7 +5,7 @@ module.exports = {
GetDB,
AddColumn,
TableInfo,
UpdateRecord,
Update,
Delete,
CreateTable,
SelectAll,
@ -83,7 +83,7 @@ function TableInfo (db, table) {
}
}
function UpdateRecord (db, table, newData, conditions) {
function Update (db, table, newData, conditions) {
try {
const s = `UPDATE ${table} SET ${GetSqlQuerry(newData)} WHERE ${GetSqlQuerry(conditions)}`
DebugLog(s)
@ -118,7 +118,8 @@ function CreateTable (db, name, columns) {
return acc
}, []).join(', ')
const s = `CREATE TABLE IF NOT EXISTS ${name}(${cols})`
// IF NOT EXISTS // TODO
const s = `CREATE TABLE ${name}(${cols})`
DebugLog(s)
const stmt = db.prepare(s)

View file

@ -118,7 +118,13 @@ function LogReq (req, toFile, sc) {
dl += C('red')
}
const hostname = req.hostname.replace('www.', '').split('.')[0]
let hostname
if (req.hostname) {
hostname = req.hostname.replace('www.', '').split('.')[0]
} else {
hostname = 'NOHOST'
Log('req.hostname is undefined! req.hostname: ' + req.hostname, GetColor('redbg'))
}
logEntry += dl + hostname + dl + req.headers['user-agent'] + dl + req.method + dl
logEntry += GetRandomColor(req.url.split('?')[0]) + req.url