Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-stats

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-stats - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

README.md

58

lib/express-stats.js
'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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc