Product
Socket Now Supports uv.lock Files
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
autoroute-base
Advanced tools
Auto-route base
is a skeleton for creating custom auto routing capabilities.
Retrieves code automatically.
Install with npm
:
npm install --save autoroute-base
See the test for a simple example.
autoroute-express-promise
example (in TypeScript - to see a vanilla JavaScript example see below).
import {createAutoRoute, method as method_} from 'autoroute-base'
import _ = require('lodash')
const toControllers = _.curry(({message, baseRoute, sendWrapper, routeName}: AutoRouteExpressPromise.ToControllersOptions, controllerMethod: AutoRouteExpressPromise.ControllerMethod) => {
const [routeMethodIndex, baseController] = controllerMethod,
methodName = method_[routeMethodIndex], // named route method
messageInfo = {routeName: routeName, methodName: methodName}
// Wrap base controller in express style callback.
baseRoute[methodName]((request: any, client: any, error: any) => {
message.call(messageInfo, messageInfo)
var send = <any> _.compose(client.send.bind(client), sendWrapper)
baseController(request).then(send).catch(error).done()
})
})
const createRoutes = _.curry((o: AutoRouteExpressPromise.Options, routeDefinitions: AutoRouteExpressPromise.RouteDefinition[]) => {
_.forEach(routeDefinitions, routeDef => {
const {route, methods} = routeDef,
startRoute = o.baseRoute(route), // Get router
options_: AutoRouteExpressPromise.ToControllersOptions = <any> _.assign({}, o, {routeName: route, baseRoute: startRoute})
_.forEach(methods, toControllers(options_)) // attach routes/methods to router
})
})
export const routes = _.curry((options: AutoRouteExpressPromise.Options, glob: string[]) => {
createAutoRoute({createRoutes: createRoutes(options), glob: glob})
})
export const method = method_
Vanilla JavaScript example of above.
var autoroute_base_1 = require('autoroute-base');
var _ = require('lodash');
var toControllers = _.curry(function (_a, controllerMethod) {
var message = _a.message, baseRoute = _a.baseRoute, sendWrapper = _a.sendWrapper, routeName = _a.routeName;
var routeMethodIndex = controllerMethod[0], baseController = controllerMethod[1], methodName = autoroute_base_1.method[routeMethodIndex], messageInfo = { routeName: routeName, methodName: methodName };
// Wrap base controller in express style callback.
baseRoute[methodName](function (request, client, error) {
message.call(messageInfo, messageInfo);
var send = _.compose(client.send.bind(client), sendWrapper);
baseController(request).then(send).catch(error).done();
});
});
var createRoutes = _.curry(function (o, routeDefinitions) {
_.forEach(routeDefinitions, function (routeDef) {
var route = routeDef.route, methods = routeDef.methods, startRoute = o.baseRoute(route), options_ = _.assign({}, o, { routeName: route, baseRoute: startRoute });
_.forEach(methods, toControllers(options_)); // attach routes/methods to router
});
});
exports.routes = _.curry(function (options, glob) {
autoroute_base_1.createAutoRoute({ createRoutes: createRoutes(options), glob: glob });
});
exports.method = autoroute_base_1.method;
import {createAutoRoute, method} from 'autoroute-base'
createAutoRoute(options)
where options
:
{
glob: string[]
_globOptions?: any
createRoutes?: (postGlobResult: any) => any
}
glob: (Required) Array of globs for files to grab. E.g.,
['./controllers/**/index.js']
. autoroute-base
uses a custom post parse
to get back the route/controllers in a cleaner manner for easy processing,
assuming you are using the same set up I used.
_globOptions: (Optional) Options used in
require-glob
.
Note, to override the autoroute-base
reducer
behaviour do {reducer: null}
(changes to native behaviour) or {reducer: CustomReducer}
.
createRoutes: (Optional) After grabbing all the files to use. It is time to
process them for your custom project. Do your post processing here. This will
use the result of the require-glob
.
method
This is an enumeration of all the express.js
methods:
get, post, put, head, delete, options, trace, copy, lock, mkcol, move, purge, propfind, proppatch, unlock, report, mkactivity, checkout, merge, "m-search", notify, subscribe, unsubscribe, patch, search, connect
E.g.,
method.get // => 0
method[0] // => "get"
FAQs
flexible autoroute, template for creating autoroutes.
The npm package autoroute-base receives a total of 11 weekly downloads. As such, autoroute-base popularity was classified as not popular.
We found that autoroute-base 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.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.