UNPKG

2.59 kBMarkdownView Raw
1# Crixalis
2
3Lightweight web framework for node.js
4
5# Features
6
7- Small, fully 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
11
12# Synopsis
13
14General usage
15
16```js
17
18var Crixalis = require('crixalis');
19
20Crixalis
21
22 /* Load plugin */
23 .plugin('shortcuts')
24
25 /* Get router object */
26 .router()
27
28 /* Add route with placeholder */
29 .get('/hello/:name', function () {
30 /* Set view for this response */
31 this.view = 'json';
32
33 /* Set data for view */
34 this.stash.json = {
35 message: ['Hello, ', '!'].join(this.params.name)
36 };
37 })
38
39 /* Add simple route */
40 .get('/info', function () {
41 var that = this;
42
43 /* Async response */
44 this.async = true;
45
46 require('fs').readFile('./package.json', function (error, result) {
47 /* Handle error */
48 if (error) {
49 that.error(500);
50 return;
51 }
52
53 /* Set response body */
54 that.body = result;
55
56 /* Send result */
57 that.render();
58 });
59 });
60
61Crixalis
62
63 /* Override default event handler */
64 .on('default', function () {
65 this.redirect('/hello/World');
66 })
67
68 /* Start server on port 8080 */
69 .start('http', 8080);
70```
71
72# Documentation
73
74Complete API docs for latest version are available [here](http://crixalis.n4kz.com).
75
76You can generate docs yourself for offline browsing using `make docs` command.
77
78# Plugins
79
80Available core plugins
81
82- `static` Serve static files
83- `compression` Compress response using `gzip` or `deflate` compression (also works with `static` plugin)
84- `jade` Use [jade](http://jade-lang.com) template engine
85- `coffee` Compile [coffee](http://coffeescript.org) for frontend on the fly
86- `less` Compile [less](http://lesscss.org) for frontend on the fly
87- `request` Thin wrapper around `http.request` and `https.request`
88- `access` Log requests to console
89- `shortcuts` Route declaration helpers, `.get()`, `.post()`, etc.
90
91# Static server
92
93Crixalis comes with simple script for serving static files
94
95```bash
96 # Start web server on port `3000` and serve files from `~/www/`
97 crixalis --port 3000 --path ~/www/
98
99 # Start web server on port `8080` and serve files from current folder
100 crixalis
101```
102
103# Copyright and License
104
105Copyright 2012, 2013 Alexander Nazarov. All rights reserved.
106
107This program is free software: you can redistribute it and/or modify
108it under the terms of the GNU Lesser General Public License as published by
109the Free Software Foundation, either version 3 of the License, or
110(at your option) any later version.