serve hashedfavicon path as png
This commit is contained in:
@ -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) {
|
||||
|
Reference in New Issue
Block a user