diff options
author | Tor Andersson <tor@ccxvii.net> | 2021-12-03 17:44:30 +0100 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2021-12-04 17:59:49 +0100 |
commit | 07c8263929fb5b46082d5c3b20a11edfb59a2b25 (patch) | |
tree | e27e0c5f56e15c3012d0457fd075d0499b1f9078 | |
parent | 628ac2e2a1bb86baf1b4456bdb0490e5486c225d (diff) | |
download | server-07c8263929fb5b46082d5c3b20a11edfb59a2b25.tar.gz |
Use compression to gzip responses.
-rw-r--r-- | public/style.css | 8 | ||||
-rw-r--r-- | server.js | 22 | ||||
-rw-r--r-- | views/index.pug | 5 | ||||
-rw-r--r-- | views/info.pug | 3 |
4 files changed, 23 insertions, 15 deletions
diff --git a/public/style.css b/public/style.css index 8290892..cfeacd6 100644 --- a/public/style.css +++ b/public/style.css @@ -37,12 +37,16 @@ img.avatar { height: 80px; } -img.logo { +div.logo { float: left; margin: 0 20px 5px 0; - box-shadow: 2px 2px 4px 0px rgba(0,0,0,0.5); + min-width: 150px; height: 200px; } +img.logo { + box-shadow: 2px 2px 4px 0px rgba(0,0,0,0.5); + height: 100%; +} table { min-width: min(50rem,100%); @@ -6,6 +6,7 @@ const http = require('http'); const https = require('https'); const socket_io = require('socket.io'); const express = require('express'); +const compression = require('compression'); const sqlite3 = require('better-sqlite3'); require('dotenv').config(); @@ -82,17 +83,12 @@ function login_delete(res, sid) { * Web server setup. */ -const is_immutable = /\.(svg|png|jpg|jpeg|woff2|webp|ico)$/; -function set_static_headers(res, path) { - if (is_immutable.test(path)) - res.set("Cache-Control", "public, max-age=86400, immutable"); -} - let app = express(); app.set('x-powered-by', false); app.set('etag', false); app.set('view engine', 'pug'); -app.use(express.static('public', { setHeaders: set_static_headers, lastModified:false })); +app.use(compression()); +app.use(express.static('public', { etag: false, maxAge: 24*3600*1000 })); app.use(express.urlencoded({extended:false})); let http_port = process.env.HTTP_PORT || 8080; @@ -269,6 +265,7 @@ function is_blacklisted(mail) { } app.use(function (req, res, next) { + res.setHeader('Cache-Control', 'no-store'); if (SQL_BLACKLIST_IP.get(req.connection.remoteAddress) === 1) return res.status(403).send('Sorry, but this IP has been banned.'); let sid = login_cookie(req); @@ -1187,6 +1184,7 @@ function update_join_clients_deleted(game_id) { res.write("retry: 15000\n"); res.write("event: deleted\n"); res.write("data: The game doesn't exist.\n\n"); + res.flush(); } } } @@ -1199,6 +1197,7 @@ function update_join_clients_game(game_id) { res.write("retry: 15000\n"); res.write("event: game\n"); res.write("data: " + JSON.stringify(game) + "\n\n"); + res.flush(); } } } @@ -1214,6 +1213,7 @@ function update_join_clients_players(game_id) { res.write("data: " + JSON.stringify(players) + "\n\n"); res.write("event: ready\n"); res.write("data: " + ready + "\n\n"); + res.flush(); } } } @@ -1271,6 +1271,7 @@ app.get('/join-events/:game_id', must_be_logged_in, function (req, res) { res.write("data: " + JSON.stringify(game) + "\n\n"); res.write("event: players\n"); res.write("data: " + JSON.stringify(players) + "\n\n"); + res.flush(); }); app.get('/join/:game_id/:role', must_be_logged_in, function (req, res) { @@ -1695,15 +1696,16 @@ io.on('connection', (socket) => { let players = SQL_SELECT_PLAYERS_JOIN.all(socket.game_id); if (socket.role !== "Observer") { - let me; + if (!socket.user_id) + return socket.emit('error', "You are not logged in!"); if (socket.role && socket.role !== 'undefined' && socket.role !== 'null') { - me = players.find(p => p.user_id === socket.user_id && p.role === socket.role); + let me = players.find(p => p.user_id === socket.user_id && p.role === socket.role); if (!me) { socket.role = "Observer"; return socket.emit('error', "You aren't assigned that role!"); } } else { - me = players.find(p => p.user_id === socket.user_id); + let me = players.find(p => p.user_id === socket.user_id); socket.role = me ? me.role : "Observer"; } } diff --git a/views/index.pug b/views/index.pug index ab5cdc9..ba915b0 100644 --- a/views/index.pug +++ b/views/index.pug @@ -12,7 +12,8 @@ html justify-content: left; } div.list div { - margin: 10px 5px; + min-width: 150px; + margin: 10px 15px; text-align: center; } div.list a:not(:hover) { @@ -22,7 +23,7 @@ html div.list img { box-shadow: 2px 2px 4px 0px rgba(0,0,0,0.5); height: 200px; - margin: 5px 10px; + margin: 5px auto; display: block; } body diff --git a/views/info.pug b/views/info.pug index d3d7da2..f73e6ef 100644 --- a/views/info.pug +++ b/views/info.pug @@ -11,7 +11,8 @@ html article h1= title.title_name - img.logo(src="/"+title.title_id+"/cover.jpg") + div.logo + img.logo(src="/"+title.title_id+"/cover.jpg") | !{ about_html } |