mirror of
https://github.com/fenwick67/mastofeed
synced 2025-01-24 16:00:59 +01:00
improve logger
This commit is contained in:
parent
e6ead57b6c
commit
d5631f54a3
19
index.js
19
index.js
@ -7,20 +7,11 @@ var serveStatic = require('serve-static');
|
|||||||
var request = require('request');
|
var request = require('request');
|
||||||
var cors = require('cors');
|
var cors = require('cors');
|
||||||
var errorPage = require('./lib/errorPage');
|
var errorPage = require('./lib/errorPage');
|
||||||
var log = console.log;
|
var morgan = require('morgan');
|
||||||
|
|
||||||
var app = Express();
|
var app = Express();
|
||||||
|
|
||||||
function logMiddleware(req,res,next){
|
var logger = morgan('tiny')
|
||||||
log(req.method.toUpperCase() +' '+ req.url);
|
|
||||||
log( '\t'+ new Date().toISOString() );
|
|
||||||
if(req.headers && req.headers.referer){
|
|
||||||
log('\tReferer: '+req.headers.referer);
|
|
||||||
}
|
|
||||||
return next(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
app.use(logMiddleware);
|
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
serveStatic('static',{
|
serveStatic('static',{
|
||||||
@ -64,7 +55,7 @@ app.get('/api/feed',cors(),function(req,res){
|
|||||||
|
|
||||||
app.options('/apiv2/feed',cors());
|
app.options('/apiv2/feed',cors());
|
||||||
// http://localhost:8000/apiv2/feed?userurl=https%3A%2F%2Foctodon.social%2Fusers%2Ffenwick67
|
// http://localhost:8000/apiv2/feed?userurl=https%3A%2F%2Foctodon.social%2Fusers%2Ffenwick67
|
||||||
app.get('/apiv2/feed',cors(),function(req,res){
|
app.get('/apiv2/feed',cors(),logger,function(req,res){
|
||||||
|
|
||||||
// get feed url
|
// get feed url
|
||||||
var userUrl = req.query.userurl;
|
var userUrl = req.query.userurl;
|
||||||
@ -118,12 +109,12 @@ app.get('/apiv2/feed',cors(),function(req,res){
|
|||||||
res.send(data);
|
res.send(data);
|
||||||
}).catch((er)=>{
|
}).catch((er)=>{
|
||||||
res.status(500);
|
res.status(500);
|
||||||
res.send(errorPage(500));
|
res.send(errorPage(500,null,{theme:opts.theme,size:opts.size}));
|
||||||
// TODO log the error
|
// TODO log the error
|
||||||
console.error(er,er.stack);
|
console.error(er,er.stack);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
app.listen(process.env.PORT || 8000,function(){
|
app.listen(process.env.PORT || 8000,function(){
|
||||||
log('listening on '+(process.env.PORT || 8000));
|
console.log('Server started, listening on '+(process.env.PORT || 8000));
|
||||||
});
|
});
|
||||||
|
@ -2,27 +2,30 @@ var ejs = require('ejs');
|
|||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var template = ejs.compile(fs.readFileSync('./lib/template.ejs', 'utf8'));
|
var template = ejs.compile(fs.readFileSync('./lib/template.ejs', 'utf8'));
|
||||||
|
|
||||||
|
module.exports = function(code,message,displayOptions){
|
||||||
module.exports = function(code,message){
|
|
||||||
|
|
||||||
|
|
||||||
var msg;
|
var msg;
|
||||||
|
var displayOptions = displayOptions || {};
|
||||||
|
|
||||||
if (code == 500 && !message){
|
if (code == 500 && !message){
|
||||||
msg = '<p>Sorry, we are having trouble fetching posts for this user. Please try again later.</p><br><p>If the issue persists, <a href="https://github.com/fenwick67/mastofeed/issues">please open an issue on GitHub</a> or message fenwick67@octodon.social</p>'
|
msg = '<p>Sorry, we are having trouble fetching posts for this user. Please try again later.</p><br><p>If the issue persists, <a href="https://github.com/fenwick67/mastofeed/issues">please open an issue on GitHub</a>, or message fenwick67@octodon.social</p>'
|
||||||
}else{
|
}else{
|
||||||
msg = message;
|
msg = message||'';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
opts:{
|
opts:{
|
||||||
header:true
|
header:true,
|
||||||
|
theme:displayOptions.theme||null,
|
||||||
|
size:displayOptions.size||null
|
||||||
},
|
},
|
||||||
meta:{
|
meta:{
|
||||||
title:code.toString(),
|
title:code.toString(),
|
||||||
description:msg,
|
description:msg,
|
||||||
link:'#'
|
link:'#'
|
||||||
|
// avatar:'',
|
||||||
|
// headerImage:''
|
||||||
},
|
},
|
||||||
items:[],
|
items:[],
|
||||||
nextPageLink:null,
|
nextPageLink:null,
|
||||||
|
32
npm-shrinkwrap.json
generated
32
npm-shrinkwrap.json
generated
@ -138,6 +138,21 @@
|
|||||||
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=",
|
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"basic-auth": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==",
|
||||||
|
"requires": {
|
||||||
|
"safe-buffer": "5.1.2"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"safe-buffer": {
|
||||||
|
"version": "5.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
||||||
|
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"bcrypt-pbkdf": {
|
"bcrypt-pbkdf": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz",
|
||||||
@ -997,6 +1012,18 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"morgan": {
|
||||||
|
"version": "1.9.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/morgan/-/morgan-1.9.1.tgz",
|
||||||
|
"integrity": "sha512-HQStPIV4y3afTiCYVxirakhlCfGkI161c76kKFca7Fk1JusM//Qeo1ej2XaMniiNeaZklMVrh3vTtIzpzwbpmA==",
|
||||||
|
"requires": {
|
||||||
|
"basic-auth": "~2.0.0",
|
||||||
|
"debug": "2.6.9",
|
||||||
|
"depd": "~1.1.2",
|
||||||
|
"on-finished": "~2.3.0",
|
||||||
|
"on-headers": "~1.0.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"mri": {
|
"mri": {
|
||||||
"version": "1.1.4",
|
"version": "1.1.4",
|
||||||
"resolved": "https://registry.npmjs.org/mri/-/mri-1.1.4.tgz",
|
"resolved": "https://registry.npmjs.org/mri/-/mri-1.1.4.tgz",
|
||||||
@ -1131,6 +1158,11 @@
|
|||||||
"ee-first": "1.1.1"
|
"ee-first": "1.1.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"on-headers": {
|
||||||
|
"version": "1.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.2.tgz",
|
||||||
|
"integrity": "sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA=="
|
||||||
|
},
|
||||||
"once": {
|
"once": {
|
||||||
"version": "1.4.0",
|
"version": "1.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
"ejs": "^2.5.8",
|
"ejs": "^2.5.8",
|
||||||
"express": "^4.16.4",
|
"express": "^4.16.4",
|
||||||
"feedparser": "^2.2.9",
|
"feedparser": "^2.2.9",
|
||||||
|
"morgan": "^1.9.1",
|
||||||
"request": "^2.88.0",
|
"request": "^2.88.0",
|
||||||
"request-promise-cache": "^2.0.1",
|
"request-promise-cache": "^2.0.1",
|
||||||
"request-promise-native": "^1.0.7",
|
"request-promise-native": "^1.0.7",
|
||||||
|
Loading…
Reference in New Issue
Block a user