⬆️ ⬇️

Autodafé

Autodafe - node.js web application development framework



The content of the article may describe irrelevant code. The framework has its autodafe.ws website for a long time .



The most delicious buns out of the box:





A spoon of tar:





')



Hello world





Next, I will describe the process of creating an application that will give only one page when entering the site root and 404 error in other cases. The main goal is to acquaint readers with the organization of the application in Autodafe.



Step 1. Prepare the file structure.





Yes, now this step is not automated.



Let's name the directory for the project hello_world, what should be in it for the simplest application:



 / hello_world
   / config will store configuration files here
     /main.js one is enough for a start
   / controllers here we will add controllers that define the logic of our outstanding application
     /site.js is the only controller with a single action for a single page.
   / views place for views
     /index.html main page view
   /index.js input script




Step 2. Install Autodafe





 cd hello_world
 npm install autodafe




Usually everything goes quite smoothly)) (tested on fedora, mint)



Step 3. File by File



The input script index.js



In it, we simply connect the configuration file, autodafe, and also create and run the application.



var config = require( './config/main' ); var autodafe = require( 'autodafe' ); autodafe.create_application( config ).run(); 




Configuration file main.js





 module.exports = { //   (       ) name : 'hello_world', //   ,        , , , // ,           base_dir : require('path').join( __dirname, '..' ), //  ,         Application.get_param params : { your_name : 'Andrey' //         }, //          router : { rules : { '/' : 'site.index' } }, //    components : { // http  http : { port : 3000 } } }; 




Site.js controller





  //   Controller module.exports = Site.inherits( global.autodafe.Controller ); /** *     ,        */ function SiteController( params ) { this._init( params ); } /** *   .      router.rules      */ SiteController.prototype.index = function ( response, request ) { //    index.html    response.send({ name : this.app.params['your_name' ] } ); }; 




And finally, our index.html view.



The only thing you need to pay attention to is the {name} parameter passed from the controller. Autodafe uses dust to render

 <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <title>Autodafe hello world</title> </head> <body> <h1>Hello {name}!</h1> </body> </html> 




Run



 node index.js


and go to localhost: 3000 in your browser



Where to learn about the framework more



Website autodafe.ws

The source code on github: autodafe , there are 3 small demos + in the common_config.js file you can see an example of setting up the application with the maximum use of all components

Follow the framework on twitter @node_autodafe



If you want to take part in the development or in any way to help in the development of the framework - write in a personal or jifeon at gmail.com

Source: https://habr.com/ru/post/135089/



All Articles