Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
grand-central-junction
Advanced tools
A simple Rails-inspired router for Node built on top of Express.
Options that can be specified:
dir
-- the home directory of the app. Defaults to the directory that contains the node_modules
folderroutes
-- the routes path, relative to the directory route() is called from. Defaults to config/routes
controllers
-- the controllers path. Defaults to controllers
In your app.js
file or wherever you initialize your Express app, add the following code:
var express = require('express'),
gcj = require('grand-central-junction'),
app = express();
gcj.route(app);
With custom options:
gcj.route(app, {
dir: __dirname + '/app',
routes: 'router/routes', // Will get the routes from ./app/router/routes.js
controllers: 'controllers' // Will look for controllers in ./app/controllers/
});
Example of /config/routes.js:
var oauth = require('../oauth');
match('/', 'home#index');
match('/user/:id', 'user#get');
match('/user', 'user#create', {via: 'post'});
put('/user/:id', 'user#update');
del('/user/:id', oauth.requireAuth, 'user#remove');
resources('/animal', 'animal');
Routes:
GET / => /controllers/home.js#index
GET /user/:id => /controllers/user.js#get
POST /user => /controllers/user.js#create
PUT /user/:id => /controllers/user.js#update
DELETE /user/:id => /oauth.js#requireAuth >> /controllers/user.js#remove
GET /animal => /controllers/animal.js#index
GET /animal/:id => /controllers/animal.js#show
POST /animal => /controllers/animal.js#create
PUT /animal/:id => /controllers/animal.js#update
DELETE /animal/:id => /controllers/animal.js#destroy
GET /animal/create => /controllers/animal.js#create
GET /animal/edit/:id => /controllers/animal.js#update
GET /animal/delete/:id => /controllers/animal.js#destroy
A GET
route to the specified controller/action.
string
regex
-- the Express routing string/RegExstring
function
-- either a direct callback with req, res
params or a string in the format of 'controller#action'
, with controller being the name of the file in the controllers directory and action being the name of the method in the controller.object
via
changes the method of the route: get
(default), post
, put
, delete
method
same as via
Same as match() options above, but without options and the ability to include many actions. VERB = get
|post
|put
|del
|all
Maps all HTTP methods to their respective CRUD actions in a controller. The action names are the same as those in Rails with a few extras added in (see above list of routes for names).
string
regex
-- the Express routing string/RegExstring
-- the name of the file in the controllers directory, so 'project'
would be the name of ./controllers/project.js
. This defaults to whatever name is in the route
string.FAQs
A simple, lightweight router for Node and Express
We found that grand-central-junction 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’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.