serve hashedfavicon path as png
This commit is contained in:
parent
82e8db0128
commit
15814cf86b
@ -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) {
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user