Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
phyesix committed Jan 26, 2022
1 parent 24f0ee3 commit ade48dd
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 1,092 deletions.
2 changes: 2 additions & 0 deletions .env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PORT=3000
HOST=localhost
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
.DS_Store
.DS_Store
.env
yarn.lock
2 changes: 1 addition & 1 deletion .nvm
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v16.2.0
v17.4.0
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ app.listen(PORT, () => {
host: HOST ? HOST : "127.0.0.1",
port: PORT,
};
console.log(`Server init on: http://:${PORT}`);
console.log(`Server init on: http://${HOST}:${PORT}`);
});
17 changes: 10 additions & 7 deletions app/controllers/favicon.controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var request = require('request');
var jsdom = require('jsdom');
const request = require('request');
const jsdom = require('jsdom');
const https = require('https');
const { JSDOM } = jsdom;

exports.getFavIcon = (req, res) => {
Expand Down Expand Up @@ -49,24 +50,26 @@ exports.getFavIcon = (req, res) => {

request(url + '/favicon.ico', function (err, resp, body) {
if (resp.statusCode === 200) {
let fullpath = url + "/favicon.ico";
res.send("<img src='" + fullpath + "'>");
fullpath = url + "/favicon.ico";
} else {
request(url, function (err, resp, body) {
if (resp.statusCode === 200) {
let dom = new JSDOM(body);
let favurl = dom.window.document.querySelector('[rel*=icon]')?.href;
let fullpath;

if(!favurl) {
fullpath = url + "/favicon.ico";
} else {
fullpath = favurl.split("/")[0] == "" ? url + favurl : favurl;
}

res.send("<img src='" + fullpath + "'>");
}
});
}

res.writeHead(200,{'content-type':'image/x-icon'});
https.get(fullpath, (stream) => {
stream.pipe(res);
});

});
};
Loading

0 comments on commit ade48dd

Please sign in to comment.