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

orangebox

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

orangebox

Lightweight Node.js web application framework on clusters with file server

  • 0.1.6
  • Source
  • npm
  • Socket score

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

OrangeBox Logo
Lightweight Node.js web application framework on clusters with file server.

How To Install

npm install orangebox

Getting Started

var app = require('orangebox').app();

app.get('/', function (req, res) {
  res.send('Hello World');
});
app.listen(8080);

After run your web server will be working in 3 threads via clusters. To specify the number of threads use:

var count = 8;
var app = require('orangebox').app(count);

Application

Routing

// invoked for any requests passed to this router
router.use(function(req, res, next) {
  // .. some logic here ..
  next();
});

// Will handle all requests that reference a /test
app.get('/test/*', function (req, res) {
  //...
});

// Will handle all requests that reference a /test
app.get('/test', function (req, res) {
  //...
});

// used named keys
app.get('/user/:id/:method', function (req, res) {
  //...
});

// routing with regexp
app.get('/^\/commits\/(\w+)(?:\.\.(\w+))?$/', function (req, res) {
  //...
});

Note: if your handler function has 3 parameters (with "next"), you should be use next(); in it body

Middleware

Mount the middleware function(s) at the path. If path is not specified, it defaults to "*".

// this middleware will be executed for every request to the app
app.use('*', function (req, res, next) {
  console.log('Time: %d', Date.now());
  next();
})

Middleware functions are executed sequentially, therefore the order of middleware inclusion is important.

// this middleware will not allow the request to go beyond it
app.use(function(req, res, next) {
  res.send('Hello World');
})

// requests will never reach this route
app.get('/test', function (req, res) {
  res.send('Hello World 2');
})

An orangebox app is a valid middleware.

var orangeBox = require('orangebox');
var app       = orangeBox.app();
var subApp    = orangeBox.app();

subApp.get('/news', function (req, res, next) {
  res.send('This news middleware');
});

app.use(subApp);

File server

For this feature used node-static Server:

var app = require('orangebox').app();

// Creating a file server for serving files under a directory
app.fileServer(__dirname + '/public');

app.get('/', function (req, res) {
  res.send('<img src="my.jpg" />');
});

// Transfer the file at the given path.  
app.get('/i/send.jpg', function (req, res) {
  res.sendFile(__dirname + '/public/send.jpg');
});

// Transfer the file as attachment at the given path. 
app.get('/i/attachment.jpg', function (req, res) {
  res.attachment(__dirname + '/public/send.jpg', "attachment.jpg");
});

// Serving files as attachments under a directory 
app.get('/attach/*.jpg', function (req, res) {
  res.attachment(__dirname + '/public/' + req.params[0] +'.jpg', "attachment-" + req.params[0] + ".jpg");
});

app.listen(8080);

Of course you need to put the pictures to the folder ./public

File upload

var app = require('orangebox').app();

app.get('/', function (req, res) {
  res.send('<form action="/upload" enctype="multipart/form-data" method="post">'+
    '<input type="text" name="title"><br>'+
    '<input type="file" name="upload" multiple="multiple"><br>'+
    '<input type="submit" value="Upload!">'+
    '</form>');
});
app.post('/upload', function (req, res) {
  res.send([req.files, req.body]);
});
app.listen(8080);

Settings

Application settings variable can be set using app.set(), and retrieved using app.get(). The following settings are provided to alter how OrangeBox will behave:

  • env Environment mode, defaults to process.env.NODE_ENV or "development"

  • case sensitive routing Enable case sensitivity, disabled by default, treating "/Foo" and "/foo" as the same

  • strict routing Enable strict routing, by default "/foo" and "/foo/" are treated the same by the router

  • view cache Enables view template compilation caching, enabled in production by default

  • view engine The default engine extension to use when omitted

  • views The view directory path, defaulting to "process.cwd() + '/views'"

Aliases In Routes

app.alias('/favicon.ico', '/favicon-test.ico');

People

Author and developer of OrangeBox is Oleksiy Chechel

List of all contributors

License

MIT License

Copyright (C) 2014 Oleksiy Chechel (alex.mirrr@gmail.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Keywords

FAQs

Package last updated on 31 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