A light-weighted nodejs framework
Run following command in terminal.
# clone the repo
git clone https://github.com/HVish/node-framework.git
# Now copy cloned repo to desired directory for your project.
rsync -av --exclude='.git' node-framework/ your-project-directory/
cd your-project-directory/
#install dependencies
npm install
The controllers are in the directory:
/app/api/
/app/web/
The views are in /views/
Layouts are in /views/layouts/
Partials are in /views/partials/
All static files are in /public/
It contains all CSS, JavaScripts and other files like images etc.
All routes are stored in routes.js There are two type of routing:
- For
API
- For
Website
The endpoint you mention will be as follows:
"METHOD URL" : "Controller_Name.Function_Name"
here METHOD
will be: {"GET", "POST", "PUT", "DELETE"}
and so on as mentioned in express.js documentation for routing methods.
The URL will automatically be prepended by the type of routing. For example:
api: {
"GET /home/books": "Home.index"
}
above will be converted to url: /api/home/books
Policies are the middlewares, generally used for intercepting url requests specified in policies.js
The policies are in the directory: /app/policies/
All policies can have only one function named as "index".
There are three type of policies:
- For all controllers
- For all handlers (functions)
- For specific handler
For all Controller/Handler, use asterisk symbol(*) as follows:
"*" : "PolicyName"
OR
"*" : ["PolicyName1", "PolicyName2"] // policies will be executed in order
The Controller/Handler Name
you mention will be as follows:
"Controller/Handler Name" : "PolicyName"
OR
"Controller/Handler Name" : ["PolicyName1", "PolicyName2"]
If in place of PolicyName
true/false is used then that Controller/Handler will be Allowed/Blocked to execute.
If "*" as well as "Controller/Handler" is not mentioned then by default that Controller/Handler will be allowed to execute.
Note: If a Controller/Handler is mentioned then it will override the policies defined by "*".
Following will be structure:
{
"api": {
"*" : PolicyName,
"Controller_1": PolicyName,
"Controller_2": {
"*": PolicyName,
"Handler_1": PolicyName,
"Handler_2": PolicyName
}
},
"web": {
"*" : PolicyName,
"Controller_1": PolicyName,
"Controller_2": {
"*": PolicyName,
"Handler_1": PolicyName,
"Handler_2": PolicyName
}
}
}