1 | ALAJS Get Started
|
2 | ====================================
|
3 | ALAJS is a simple mvc framework based on [koa](https://github.com/koajs/koa).Thank you very much, you are a great middle framework!
|
4 |
|
5 | ###1. Install
|
6 |
|
7 | 1. npm install alajs --save
|
8 | 2. npm -g install node-dev
|
9 |
|
10 |
|
11 | ###2. Create app.js file and require alajs
|
12 |
|
13 | var alajs = require('alajs');
|
14 |
|
15 | ###3. Define an App
|
16 |
|
17 | App = alajs({ /*please set the App to gobal*/
|
18 | name : 'ALABLOG',
|
19 | databases : {
|
20 | default: 'mysql:root@localhost/test',
|
21 | log : 'mongodb://localhost/test'
|
22 | },
|
23 | models : ['/share/models']
|
24 | });
|
25 |
|
26 |
|
27 | ###4. Define a module
|
28 |
|
29 | App.define.module({
|
30 | name : 'root',
|
31 | url : '/',
|
32 | path : '/app',
|
33 | controllers : ['/controllers','/otherCtrls'],
|
34 | staticResources : '/static',
|
35 | })
|
36 |
|
37 | ###5. Set default module
|
38 |
|
39 | App.define.defaultModule('root');
|
40 |
|
41 | ###6. Define a server
|
42 |
|
43 | var server = App.define.server({port:3000});
|
44 |
|
45 | ###7. Load App to server
|
46 |
|
47 | server.loader(App);
|
48 |
|
49 | ###8. Startup server
|
50 |
|
51 | server.bootstrap();
|
52 |
|
53 | ###9. Create a welcome.js file in controllers folder and define a controller
|
54 |
|
55 | var welcome = App.define.controller({name:'welcome',url:'/welcome'})
|
56 |
|
57 | ###10. Define an action function for response
|
58 |
|
59 |
|
60 | welcome('you',function *(next){
|
61 |
|
62 | this.body = 'You are welcome!'
|
63 |
|
64 | })
|
65 |
|
66 | ###11. Start this app
|
67 |
|
68 |
|
69 | node-dev --debug --harmony app.js
|
70 |
|
71 | ###12. Visit [http://localhost:3000/welcome/you](http://localhost:3000/welcome/you)
|