JS Micro-Framework
Clone the repo
git clone https://github.com/tanguyprvst/Lucid.git
Install NPM packages
npm install
Create a controller in app/controllers
const Controller = require('../../src/app/controller');
class ExempleController extends Controller {
}
module.exports = ExempleController
Create your routes and methods!
const Controller = require('../../src/app/controller');
class ExempleController extends Controller {
getRoutes(){
return [
['/', 'get', this.exempleFunc],
]
}
exempleFunc(res){
this.render(res, {value: "Hello"});
}
}
GET method:
['/', 'get', this.exempleFunc]
exempleFunc(res){ //Todo: code }
POST method:
['/', 'post', this.exempleFunc]
exempleFunc(res, request){ //Todo: code }
Route with parameter:
['/tickets/{id}', 'get', this.exempleFunc]
exempleFunc(res, id){ //Todo: code }
Create a controller in app/middlewares
class ExempleMiddleware {
static handle(res, request, next){
return next(res, request);
}
}
module.exports = ExempleMiddleware
In your controller, import your middleware
const ExempleMiddleware = require('../middlewares/ExempleMiddleware');
And use your middleware by changing your route!
['/', 'get', this.exempleFunc, ExempleMiddleware]
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.