nodeframe
v0.2.0
Published
A modular web application framework based-on popular node technologies (express, swig and etc.).
Downloads
4
Maintainers
Readme
Nodeframe
A modular web application framework based-on popular node technologies (express, swig and etc.).
License
MIT
Latest version
0.2.0
Quick Start
1). Bootstrapping nodeframe.
Write a "package.json" file as below.
{ "name": "Project Name", "version": "0.0.1", "private": true, "scripts": { "start": "node app-server.js" }, "dependencies": { "nodeframe": "*" } }
Run "npm install" under the same directory with "package.json".
Write a "app-server.js" file as below.
require('nodeframe').start();
Run "node app-server.js".
Try visit http://localhost:3000
2). Create a new web module.
Create a module directory "hello_nodeframe" under the "web_modules" directory which is automatically created by previous operations.
Write a "bootstrap.js" as below under the newly created directory.
module.exports = { version: '0.0.1', // the version of the new module routes: { // routes settings '/': { rule: { // router type, currently supports rule/mvc/rest rules: { // required for rule based router '/': { // sub-path get: 'home.index' // http method and controller action } } } } } };
Create a controllers directory "controllers" under the "hello_nodeframe" directory.
Write the controller file "home.js" as below under the "controllers" directory.
module.exports = { index: function (router) { // controller action router.appendViewData({ title: 'Hello nodeframe!' }); // to render "index" view template, modify router.view to render other template router.renderResponse(); } };
Create a views directory "views" under the "hello_nodeframe" directory.
Write the view template "home_index.swig" as below under the "views" directory.
{{ title }}
Update the "etc/development.js" file that generated by 1) as below to enable the new module.
module.exports = { modules: { hello_nodeframe: { route: '/hello' // can be whatever path you want, e.g. /test, /module1 } } };
Run "node app-server.js" again.
Try visit http://localhost:3000/hello
3). Create a wechat module.
Create a module directory "hello_wechat" under the "web_modules" directory.
Write a "bootstrap.js" as below under the "hello_wechat" directory.
module.exports = { version: '0.0.1', // the version of the new module routes: { // routes settings '/': { rule: { // router type, currently supports rule/mvc/rest rules: { // required for rule based router '/': 'wechat.service' } } } }, middlewares: { 'wechat': { token: 'your_wechat_token_here' } } };
Create a controllers directory "controllers" under the "hello_wechat" directory.
Write the controller file "wechat.js" as below under the "controllers" directory.
module.exports = { service: function (router) { var message = router.req.weixin; if (message.MsgType === 'event') { if (message.Event === 'subscribe') { return router.res.reply('Welcome to subscribe!'); } return router.res.reply('I am fine.'); } if (message.MsgType === 'text') { return router.res.reply(message.Content); } router.res.reply('Hi'); } };
Update the "etc/development.js" file that generated by 1) as below to enable the new module.
module.exports = { wechat: {}, modules: { hello_nodeframe: { route: '/hello' // can be whatever path you want, e.g. /test, /module1 }, hello_wechat: { route: '/wechat' // can be whatever path you want, e.g. /test, /module1 } } };
Run "node app-server.js" again.
Try visit http://localhost:3000/wechat, and you should see "invalid signature".
Now you can use this web module as the back-end application to serve wechat request. (PS: Wechat requires the service to listen on 80 port.)