expressjs / serve-favicon Goto Github PK
View Code? Open in Web Editor NEWfavicon serving middleware
License: MIT License
favicon serving middleware
License: MIT License
Hi there, I saw res._headers
in https://github.com/expressjs/serve-favicon/blob/master/index.js#L167, but I have found nothing about that in Node.js documentation. Here are my test code on res._headers
:
Node.js:
http.createServer((req, res) => {
res.setHeader('Content-Type', 'application/json')
console.log(res._headers) // { 'content-type': 'application/json' }
res.end('done')
}).listen(9000)
curl(1): curl localhost:9000
So I guess res._headers
represent all headers that set by res.setHeader
method, am I right?
I could find the npm package name to install this - please advise what it is? I will send a PR with updated readme if you can provide this.
content is the same with title.
The last version (1.0.0) in NPM contains a bad default path (../public/favicon.ico) that throws a HTTP/500 error.
Could you please publish the HEAD version with the good default path ?
Something like this?
app.use(favicon('https://d1ir1l1v07ijd0.cloudfront.net/img/ico/favicon.ico'));
var maxMaxAge = 60 * 60 * 24 * 365 * 1000; // 1 year
vs
The cache-control max-age directive in ms, defaulting to 1 day.
<html><body>You are being <a href="https://raw.github.com/senchalabs/connect/master/lib/public/favicon.ico">redirected</a>.</body></html>
:)
I serve multiple domains from a single Express app and would like to be able to change the favicon for each domain. ie: I want to vary the image file I choose to pass to favicon() based on req.hostname. The hostnames are chosen by the users and are sometimes only different by the sub-domain.
I can't see a way to vary the favicon chosen based on req.hostname and reading this issue it seems there may not be a way to do so.
It works with Firefox/Edge. It doesn't work with Chrome (Windows/Android, latest versions).
This works (creates a lot of favicon variants)
https://www.favicon-generator.org/
This library should upgrade its dependency of fresh
to version 0.5.2
, because version 0.5.1
has a Regular Expression Denial of Service vulnerability.
$ npm i -g nsp
$ nsp check
(+) 1 vulnerabilities found
┌───────────────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ │ Regular Expression Denial of Service │
├───────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Name │ fresh │
├───────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ CVSS │ 7.5 (High) │
├───────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Installed │ 0.5.1 │
├───────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Vulnerable │ < 0.5.2 │
├───────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Patched │ >= 0.5.2 │
├───────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Path │ [email protected] > [email protected] │
├───────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ More Info │ https://nodesecurity.io/advisories/526 │
└───────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
This module is a bit rigid at the moment in that it blows up right away if it isn't given a path to an existent favicon file.
Would be a bit easier to use if, in the case no favicon exists at the given path, the middleware just returns 404 for any favicon request.
Can submit a pull request if you agree with this semantic.
Also, FAVICONS 💃
The browser keeps showing an error says :-
for the favicon.ico automatic Get request by the browser
for my localhost Get request
It would be useful to add the ability to allow us to serve a favicon directly from the controller it self so for example on the homepage you'd use the default global favicon and on the user page you may use a different favicon.
Hi. Favicon is showing when I run server locally with express (http://localhost:3000). But when I run it on production server (http://test.server.com/prod-test/myapp), It isn't working at all.
Would it be possible to support svg elements to retain a crisp definition?
Either way thank you! It is very cool.
Hello!
Is there possibility to disable etag for favicon, like in static middleware?
app.use(express.static('public', { etag: false }));
just created a new express app using 3.5.0 and get the following:
Error: ENOENT, open '/Users/matt/development/knowjs/node_modules/express/node_modules/connect/node_modules/static-favicon/../public/favicon.ico'
this is using the standard, generated:
app.use(express.favicon());
which is exported from connect, which seems to just be a require('static-favicon'); ... which led me here. ;) let me know if this issue should go somewhere else.
Cheers and thanks for the great lib!
I was just wondering why the serve-favicon signature doesn't look like this:
app.use(__dirname + '/public/favicon.ico', favicon)
The way it's written now all the code in index.js must get executed to return the function which finally checks if it's even the correct url. This happens for EVERY SINGLE REQUEST!
Shouldn't express check upfront if it's the right path before executing any code!?
I'm creating a template based express app and I want to change the favicon according with the different template selected. Is this possible with serve-favicon ?
I copy the example code in the README, it works well in Chrome and IE, but fail to show favicon in Edge
I've never understood the purpose of this middleware. favicon.ico is a static file, so it would go in your project's static resource directory and could be served by the general purpose static file serving middleware, couldn't it? Why should there be a dedicated middleware to handle this specific static file? The answers to these questions should be added to the readme.
I have a file named favicon.png and want to use it with serve-favicon.
You should update the npm package to 2.0.1, as it's still on 2.0.0-alpha.
as I understand this package gets local path for favicon. what if my favicon is at http://domain.com/favicon.ico
?
I can't give it this string as path.
@defunctzombie can you add me to the npm package?
Given that there are different requirements for all environments (Apple mobile, Windows, windows mobile etc.) is it possible to either a) document the best way to handle this in Express/serve-favicon or b) update the module to handle this use case.
The best (most robust) mark-up seems to be:
<link rel="apple-touch-icon" sizes="57x57" href="/apple-touch-icon-57x57.png">
<link rel="apple-touch-icon" sizes="114x114" href="/apple-touch-icon-114x114.png">
<link rel="apple-touch-icon" sizes="72x72" href="/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="144x144" href="/apple-touch-icon-144x144.png">
<link rel="apple-touch-icon" sizes="60x60" href="/apple-touch-icon-60x60.png">
<link rel="apple-touch-icon" sizes="120x120" href="/apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" sizes="76x76" href="/apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" sizes="152x152" href="/apple-touch-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon-180x180.png">
<link rel="icon" type="image/png" href="/favicon-192x192.png" sizes="192x192">
<link rel="icon" type="image/png" href="/favicon-160x160.png" sizes="160x160">
<link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96">
<link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16">
<link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32">
<meta name="msapplication-TileColor" content="#60000c">
It's currently unclear if all of these icons will resolve based on serve-favicon alone and I'm pretty sure that a solution could be arranged using static, it would be great if there's a way to configure serve-favicon so that it's readily apparent that paths to all of these files were made available via serve-favicon.
Ready to help in any way that I can.
Favicon is not showing except http://localhost:3000/
rout
We have a white label application that serves up the same application but branded for multiple customers. It would be great if this would serve up a different favicon based on what host is currently being called. Perhaps a callback would be the most flexible mechanism as that would keep the library implementation simpler. Cacheing might be keyed on the path that is returned by the callback.
Error: Cannot find module 'ms'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (d:\Repos\Project\node_modules\serve-favicon\index.js:16:10)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
Just got this after updating to the newest release (2.1.0)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.