diff --git a/lib/server.js b/lib/server.js index 6c74c56..063b484 100644 --- a/lib/server.js +++ b/lib/server.js @@ -6,6 +6,9 @@ const serveStatic = require('serve-static') const logger = require('./logger') +const HASHED_FAVICON_URL = '/hashedfavicon_' +const HASHED_FAVICON_EXTENSION = '.png' + function getRemoteAddr (req) { return req.headers['cf-connecting-ip'] || req.headers['x-forwarded-for'] || req.connection.remoteAddress } @@ -25,7 +28,7 @@ class Server { this._http = http.createServer((req, res) => { logger.log('info', '%s requested: %s', getRemoteAddr(req), req.url) - if (req.url.startsWith('/hashedfavicon?')) { + if (req.url.startsWith(HASHED_FAVICON_URL) && req.url.endsWith(HASHED_FAVICON_EXTENSION)) { this.handleFaviconRequest(req, res) } else { // Attempt to handle req using distServeStatic, otherwise fail over to faviconServeStatic @@ -38,7 +41,8 @@ class Server { } handleFaviconRequest = (req, res) => { - const hash = req.url.split('?')[1] + let hash = req.url.substring(HASHED_FAVICON_URL.length) + hash = hash.substring(0, hash.length - HASHED_FAVICON_EXTENSION.length) for (const serverRegistration of this._app.serverRegistrations) { if (serverRegistration.faviconHash && serverRegistration.faviconHash === hash) { diff --git a/lib/servers.js b/lib/servers.js index 61777e2..11b8d3d 100644 --- a/lib/servers.js +++ b/lib/servers.js @@ -5,6 +5,9 @@ const TimeTracker = require('./time') const config = require('../config') const minecraftVersions = require('../minecraft_versions') +const HASHED_FAVICON_URL = '/hashedfavicon_' +const HASHED_FAVICON_EXTENSION = '.png' + class ServerRegistration { serverId lastFavicon @@ -239,7 +242,7 @@ class ServerRegistration { getFaviconUrl () { if (this.faviconHash) { - return '/hashedfavicon?' + this.faviconHash + return HASHED_FAVICON_URL + this.faviconHash + HASHED_FAVICON_EXTENSION } else if (this.data.favicon) { return this.data.favicon }