Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
ampersand-controller-router
Advanced tools
Allows you to map "controllers" to routes.
var AmpRouter = require('ampersand-controller-router');
var myRouter = new AmpRouter({
// A map of controller constructors. Name is important.
controllers: {
index: require('index-controller'),
profile: require('profile-controller'),
},
// Passed to the controller constructor. I use this to pass a reference to
// my "app" object for example:
controllerOptions: {
app: appInstance,
},
// Function passed to the route action. I use this to update the current view
// and stuff.
routeCallback: appInstance.routeHandler.bind(appInstance),
// And finally your actual routes. Remember that leading `/` is not necessary
// and won't actually do what you think.
routes: {
'': 'index.home', // On `/` execute the `home` method on the `index` controller
'/profile': 'profile.user',
}
});
// Start the router.
// Accepts the same arguments as the original `ampersand-router`. But has
// slightly different defaults:
//
// pushState: true
// hashChange: false
// silent: false
// root: '/'
//
// This means that `start()` will execute the _current_ URL and won't use # for
// routing but rather "real" URLs.
myRouter.start();
This router extends the original ampersand-router and all the same events etc should be emitted.
I usually make my "controllers" subclasses of ampersand-state
. And the action
method will call the callback with an error or an instance of an ampersand-view
.
So something like this:
var AmpState = require('ampersand-state');
module.exports = AmpState.extend({
app: null,
// Constructor passed the `controllerOptions` given to the router.
initialize: function (controllerOptions) {
this.app = controllerOptions.app;
},
// A route handler
// At the moment the controller action will _always_ be passed a query
// argument, this is the query string. Should the route accept any parameters,
// like: `user/:id` that parameter will come _before_ `query`.
home: function (query, callback) {
// This is where I configure models etc. The controller is often the "owner"
// of those models. And the view's model will be the controller itself.
var view = new HomeView({model: this });
// The `routeCallback` will take this view object and replace the current
// main view with this new view.
callback(null /* no error occured */, view);
}
});
That's a sample of how I use this. For some history on it's origins check out my blog post building an app with Ampersand.
This is a very thin wrapper (~70 LOC including comments) around ampersand-router
.
It currently has no tests but have been working fine for me! :)
MIT
FAQs
Allows you to map "controllers" to routes.
We found that ampersand-controller-router 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.