Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
A simple MVC framework based on Express
npm install advanced -g
# create demo
advanced new app
# install app
cd app
npm install
# start app
node server.js
Visit http://localhost:8586
Controllers are placed in app/controllers
.
For example app/controllers/test.js
:
var Controller = require('advanced').Controller;
module.exports = Controller.extend({
index: function() {
this.res.send('Hello World!');
}
});
Visit http://localhost:8586/test
Router inherits Router of Express. But there are some enhanced features.
You can use a string to specify a controller and a method. i.e. controller@method
In app/routes.js
var Router = require('advanced').Router,
router = Router();
// a string to specify a controller and a method. i.e. controller@method
router.get('/test/add/:id(\\d+)', 'test@addTest');
module.exports = router;
Specify routes with group. It likes router.use
. The difference is that you don't need to create a router manually.
var Router = require('advanced').Router,
router = Router();
router.get('/group', function(router) {
router.get('/a', 'test@a'); // /group/a
router.get('/b', 'test@b'); // /group/b
}
module.exports = router;
A simple router based on file of controller is supported.
If doesn't match any custom router, it will go here.
For example:
req.path = '/this/is/a/path'
/this/is/a/path/index.js@index
/this/is/a/path.js@index
/this/is/a.js@path
/this/is.js@a
, this.req.params[0] = 'path'
If set env = 'development
in config.js
, it will load the middleware of mock
. The request which created by invoking Cotroller::request
method will be mocked.
For example. Assume that the request path is /test/api
. If there is a json file which path is /mock/test/api.json
, the json data will be sent by reading the file.
Add debug=true
to query string. When you want render template, in development mode, it will output json data which will render the template.
For example: Visit http://127.0.0.1:8586/?debug=true will get
{
"test": 1
}
This method uses request module.
Call Controller::request
to create a request in node. A promise will be returned. The arguments pass to the function likes below.
The baseUrl is
Utils.c('api')
which assigned tothis._api
{
dataKey1: '/path1',
datakey2: '/path2'
}
The data returned likes below.
{
dataKey1: {...},
dataKey2: {...}
}
The response data will be assigned to the corresponding key totally. But you can filter the response data by overriding the _filerData
method.
module.exports = Controller.extend({
_filterData: function(data) {
return data.data;
},
index: function() {
this.request({
dataKey1: '/path1',
datakey2: '/path2'
}).then(function(data) {
this.render('templates/index.swig', data);
}.bind(this));
}
})
MIT
FAQs
A simple MVC framework based on Express
We found that advanced demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.