New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

minipress

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

minipress

Minimal routing and config for Express

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-83.33%
Maintainers
1
Weekly downloads
 
Created
Source

minipress

Minimal routing and config for Express

Create 1 file app.js

  require('minipress')('router.json', 'config.json');

routing

Create 1 file router.json

{
  
  "GET /user/:name": [
    "middlewares/check_logged_in",
    "controllers/user.get"
  ],

  "POST /user": "controllers/user.create",

  "GET /login": "controllers/login.render",

  "POST /login": "controllers/login.auth",

  "GET /logout": "controllers/logout"
  
}

Create the associated controller/middleware files, examples:

File middlewares/check_logged_in.js

module.exports = function(req, res, next) {

  if (req.session.isLogged)
    next();
  else
    res.send('Please <a href="/login">login</a>');

};

File controllers/user.js

var User = require('../models/user');

exports.get = function(req, res) {
  
  User.get(req.params.name, function(err, user) {
    if (err || !user) {
      res.send('Could not find user: ' + req.params.name);
    } else {
      res.json(user);  
    }
  });
  
};

exports.create = function(req, res) {

  User.create({
    name: req.body.name,
    password: req.body.password
  }, function(err) {
    if (err)
      res.send('Invalid user');
    else
      res.send('User created');
  });

};

config

Create 1 file config.json

[
  "config/init",
  "config/db",
  "config/logger",
  "config/views",
  "config/session",
  "config/body_parser",
  "config/static",
  "config/error_handler"
]

Create the associated config files, example: config/logger

var morgan = require('morgan');

module.exports = function(app, next) {

  if (app.get('env') === 'production')
    app.use(morgan('common'));
  else
    app.use(morgan('dev'));

  next();

};

Keywords

FAQs

Package last updated on 21 Jan 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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