UNPKG

2.2 kBMarkdownView Raw
1# Crixalis
2
3Lightweight web framework for node.js
4
5# Features
6
7- Small, documented and easily extendable core
8- Advanced routing system (content type, method, host) with RegExp support and placeholders
9- Compression support (gzip, deflate)
10- Static file serving support (with __ETag__, __Last-Modified__, __Expires__ and LRU-cache)
11
12# Synopsis
13
14General usage
15
16```js
17
18var Crixalis = require('crixalis');
19
20Crixalis
21
22 /* Load plugins */
23 .plugin('shortcuts')
24 .plugin('access', { format: '%7T %-4m %s %9B %-15h %U%q' })
25
26 /* Add route with placeholder */
27 .get('/hello/:name', function () {
28 /* Prepare data for response */
29 this.stash.json = {
30 message: 'Hello, ' + this.params.name + '!'
31 };
32
33 /* Render response */
34 this.render();
35 })
36
37 /* Add another route for GET and HEAD methods */
38 .route('/info', { methods: ['GET', 'HEAD'] }, function () {
39 var that = this;
40
41 require('fs').readFile('./readme.md', function (error, result) {
42 if (error) {
43 /* Handle error */
44 that.error(error);
45 } else {
46 that.body = result;
47 that.render();
48 }
49 });
50 })
51
52 /* Catch everything else */
53 .route('*', function () {
54 this.redirect('/hello/World');
55 })
56
57 /* Start server on port 8080 */
58 .start('http', 8080);
59```
60
61# Plugins
62
63Available core plugins
64
65- `access` Access log (with configurable CLF support)
66- `compression` Compress response using `gzip` or `deflate` compression (also works with `static` plugin)
67- `request` Thin wrapper around `http.request` and `https.request`
68- `shortcuts` Route declaration helpers, `.get()`, `.post()`, etc.
69- `static` Serve static files
70
71# Static server
72
73Crixalis comes with script for serving static files
74
75```bash
76 # Start web server on port `8080` and serve files from current folder
77 crixalis
78
79 # Start web server on port `3000` and serve files from `~/www/`
80 crixalis --port 3000 --path ~/www/
81```
82
83# Copyright and License
84
85Copyright 2012-2016 Alexander Nazarov. All rights reserved.
86
87This program is free software: you can redistribute it and/or modify
88it under the terms of the GNU Lesser General Public License as published by
89the Free Software Foundation, either version 3 of the License, or
90(at your option) any later version.