mirror of
https://github.com/fenwick67/mastofeed
synced 2024-12-23 07:38:10 +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 cors = require('cors');
|
||||
var errorPage = require('./lib/errorPage');
|
||||
var log = console.log;
|
||||
var morgan = require('morgan');
|
||||
|
||||
var app = Express();
|
||||
|
||||
function logMiddleware(req,res,next){
|
||||
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);
|
||||
var logger = morgan('tiny')
|
||||
|
||||
app.use(
|
||||
serveStatic('static',{
|
||||
@ -64,7 +55,7 @@ app.get('/api/feed',cors(),function(req,res){
|
||||
|
||||
app.options('/apiv2/feed',cors());
|
||||
// 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
|
||||
var userUrl = req.query.userurl;
|
||||
@ -118,12 +109,12 @@ app.get('/apiv2/feed',cors(),function(req,res){
|
||||
res.send(data);
|
||||
}).catch((er)=>{
|
||||
res.status(500);
|
||||
res.send(errorPage(500));
|
||||
res.send(errorPage(500,null,{theme:opts.theme,size:opts.size}));
|
||||
// TODO log the error
|
||||
console.error(er,er.stack);
|
||||
})
|
||||
})
|
||||
|
||||
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 template = ejs.compile(fs.readFileSync('./lib/template.ejs', 'utf8'));
|
||||
|
||||
|
||||
module.exports = function(code,message){
|
||||
|
||||
module.exports = function(code,message,displayOptions){
|
||||
|
||||
var msg;
|
||||
var displayOptions = displayOptions || {};
|
||||
|
||||
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{
|
||||
msg = message;
|
||||
msg = message||'';
|
||||
}
|
||||
|
||||
|
||||
var options = {
|
||||
opts:{
|
||||
header:true
|
||||
header:true,
|
||||
theme:displayOptions.theme||null,
|
||||
size:displayOptions.size||null
|
||||
},
|
||||
meta:{
|
||||
title:code.toString(),
|
||||
description:msg,
|
||||
link:'#'
|
||||
// avatar:'',
|
||||
// headerImage:''
|
||||
},
|
||||
items:[],
|
||||
nextPageLink:null,
|
||||
|
32
npm-shrinkwrap.json
generated
32
npm-shrinkwrap.json
generated
@ -138,6 +138,21 @@
|
||||
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=",
|
||||
"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": {
|
||||
"version": "1.0.2",
|
||||
"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": {
|
||||
"version": "1.1.4",
|
||||
"resolved": "https://registry.npmjs.org/mri/-/mri-1.1.4.tgz",
|
||||
@ -1131,6 +1158,11 @@
|
||||
"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": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||
|
@ -4,6 +4,7 @@
|
||||
"ejs": "^2.5.8",
|
||||
"express": "^4.16.4",
|
||||
"feedparser": "^2.2.9",
|
||||
"morgan": "^1.9.1",
|
||||
"request": "^2.88.0",
|
||||
"request-promise-cache": "^2.0.1",
|
||||
"request-promise-native": "^1.0.7",
|
||||
|
Loading…
Reference in New Issue
Block a user