active1.0.11 • Public • Published
High performance, extendable solution with less unnecessary features. Achieve the maximum possible speed of NodeJS framework!
$ npm install active --save
const active = ;const app = ;http;
Using next method you can change application settings. All settings are optional.
- cors - cross-origin resource sharing, read details here
- debug - application with enabled debug mode prints speed for each request
For adding new routing rule, you should use addRoute method:
- method - HTTP method, can be GET, POST, PUT, DELETE (optional)
- url - pattern for request url (required)
- match - patterns for special parameters in request url (optional)
- query - patterns for query string parameters, after question mark (optional)
- fileParsing - framework parses (if true) or doesn't parse (if false) request's body for uploaded files if Content-Type is multipart/form-data (optional)
This is how you can handle client's requests.
You can do it with typical way:
Or with custom way which is provided by ActiveJS:
Few examples how you can use it:
While processing client's request you can get access to internal variables in req object:
- req.client_ip - client's IP address
- req.referer - client's referrer, identifies URL that linked to resource being requested
- req.params - URL parameters
- req.query - query string parameters
- req.files - name, extension, mime and content of uploaded file
- req.route - current route rule
Basically this is a simple way to do something with req and res objects while processing client's requests, e.g. add authorization logic before API callback runs. In ActiveJS we know this feature as layers.
You can define layers using two ways:
Will be executed for request matched specific route rule:
Will be executed for each request (all routes):
If you want to use few layers, you must send array with functions, instead of one function:
We collected some advices for you, it can be useful in some cases.
Page not found
If some client's request doesn't match your routing rules, our framework will shows blank page with 404 http status. Of course for production we need more intelligent solution, so here is example how you can show your custom "not found" page:
Just need add new routing rule for processing all requests. Important thing: this rule must be last one - just in case to overwrite previous, it's very important.
After installing of all dependencies you can run tests:
You can help to improve "Active" framework, there is lot of work to do:
- review pull requests
- find new issue or fix existing
- add new feature or improve old
- update documentation
The Active JS framework is open-source software licensed under the MIT