express-stats
Advanced tools
Comparing version 0.0.6 to 0.0.7
'use strict'; | ||
var fs = require('fs'), | ||
path = require('path'), | ||
root = path.normalize(__dirname + '../../../..'); | ||
var express = require('express'), | ||
fs = require('fs'), | ||
path = require('path'); | ||
module.exports = createMethods; | ||
// enable cors | ||
// provide swagger in /views/swagger.json | ||
// mkdir /logs and chmod 700 -R /logs | ||
// provide /logs/error.log /logs/forever.log /logs/console.log | ||
// options = { hostname: 'example.com', basePath: '/v0' } | ||
function createMethods(app, options) { | ||
function createMethods(options) { | ||
if (!options) { | ||
options = { hostname: 'localhost', basePath: '' }; | ||
options = { hostname: 'localhost', auth: noAuth(), logPath: logPath() }; | ||
} else { | ||
options.basePath = (!options.basePath ? '' : options.basePath); | ||
options.hostname = (!options.hostname ? 'localhost' : options.hostname); | ||
options.auth = (!options.auth ? noAuth() : options.auth); | ||
options.logPath = (!options.logPath ? logPath() : options.logPath); | ||
} | ||
var router = express.Router(); | ||
app.set('views', root + '/views'); | ||
app.engine('json', require('ejs').renderFile); | ||
// GET /system/logs/{logType} | ||
app.get(options.basePath + '/system/logs/:logType', function (req, res) { | ||
router.get(options.basePath + '/system/logs/:logType', function (req, res) { | ||
var options = { headers: { 'Content-Type': 'text/html; charset=utf-8' }}; | ||
res.sendFile(logType(req.params.logType), options); | ||
res.sendFile(logType(req.params.logType, options), options); | ||
}); | ||
// DELETE /system/logs/{logType} | ||
app.delete(options.basePath + '/system/logs/:logType', function (req, res) { | ||
fs.writeFile(logType(req.params.logType), 'Nothing here', function (err) { | ||
router.delete(options.basePath + '/system/logs/:logType', function (req, res) { | ||
fs.writeFile(logType(req.params.logType, options), 'Nothing here', function (err) { | ||
if (err) { return res.status(500).send(err); } | ||
@@ -40,3 +33,3 @@ res.status(200).send('OK'); | ||
// GET /system/swagger | ||
app.get(options.basePath + '/system/swagger', function (req, res) { | ||
router.get(options.basePath + '/system/swagger', function (req, res) { | ||
res.render('swagger.json', { hostname: options.hostname }); | ||
@@ -46,3 +39,3 @@ }); | ||
// GET /system/mem | ||
app.get(options.basePath + '/system/mem', function (req, res) { | ||
router.get(options.basePath + '/system/mem', function (req, res) { | ||
var mem = process.memoryUsage(); | ||
@@ -52,11 +45,24 @@ var used = (mem.heapUsed / mem.heapTotal).toFixed(2); | ||
}); | ||
return router; | ||
} | ||
function logType (str) { | ||
var path = root + '/logs/'; | ||
function logType (str, options) { | ||
if (str === 'err' || str === 'error') { | ||
return path + 'error.log'; | ||
return options.logPath + 'error.log'; | ||
} else if (str === 'for' || str === 'forever') { | ||
return path + 'forever.log'; | ||
} else return path + 'console.log'; | ||
return options.logPath + 'forever.log'; | ||
} else return options.logPath + 'console.log'; | ||
} | ||
function noAuth () { | ||
return function (req, res, next) { | ||
next(); | ||
}; | ||
} | ||
function logPath() { | ||
return path.normalize(__dirname + '../../../../logs/'); | ||
} | ||
module.exports = createMethods; |
{ | ||
"name": "express-stats", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "Runtime statics for express production servers", | ||
@@ -14,3 +14,4 @@ "main": "app.js", | ||
"dependencies": { | ||
"express": ">=4.12.3" | ||
"express": ">=4.12.3", | ||
"cors": ">=2.5.3" | ||
}, | ||
@@ -17,0 +18,0 @@ "repository": "georgschlenkhoff/express-stats", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
4934
5
54
1
111
2
+ Addedcors@>=2.5.3
+ Addedcors@2.8.5(transitive)
+ Addedobject-assign@4.1.1(transitive)