anotheri / express-routescan Goto Github PK
View Code? Open in Web Editor NEWAutomatic file scanner for Express JS router.
License: MIT License
Automatic file scanner for Express JS router.
License: MIT License
Right now single route ("/api/abc") with more than one method ( GET, POST) can point to single function.
E. g.
module.exports = {
'/api/abc' : {
method: ['get','post'],
fn: functionForBothGetAndPost
}
}
It would be helpful if library provides a way to point to different function for different method.
E.g. Something like this:
module.exports = {
'/api/abc' : {
method: ['get','post'],
fn: [functionForGet, functionForPost]
}
}
Do you have any recommended ways to pass in parameters to the routes from the main express application. For example, if my route files need access to the http server object is there a good way to give the route files themselves access to that? Thanks!
Right now, the routes defined always start from the root. Would it be possible to add an option/parameter to set a custom prefix, which is then prefixed to every route (or every route in a specific routes directory)? (For example: /api)
Hi,
I've just started playing with this module, but I've been unable to recreate my previous fall-through route, where I would define app.use()
with no route parameter and catch all invalid routes.
I can't seem to find a way of doing this using express-routescan, as if I use a blank route param it throws up an error.
Any ideas? Or am I missing something!
Many thanks
Matt
Ps, at the moment my only option is to define a /404
route using routescan, and then at the end of my app.js file, putting a redirect, but I want to keep the broken path rather than redirecting:
app.use(function (req, res) {
res.redirect('/404');
});
Maybe "fn" in the route hashtable should be optional. It is valid just to define a middleware.
My use case is to register passport.js routes:
module.exports = {
'/auth/twitter': {
method: 'GET',
middleware: [passport.authenticate('twitter')]
},
'/auth/twitter/callback': {
method: 'GET',
middleware: [passport.authenticate('twitter', {
successRedirect: '/',
failureRedirect: '/login'
})]
}
};
This works... just needed a full setup example :)
Initialized routes:
# GET /
# POST /word2html
Statistic info:
[routed]:
1. C:\dev-projects\node-projects\word2html\routes\index.js GET /
Done.
Listening on port: 8080
App started
Simple setup:
http = require 'http'
express = require 'express'
routescan = require 'express-routescan'
app = express!
port = 8080
app.set 'port', port
# start express-routescan.
routescan app, verbose: true
http.create-server(app).listen port, ->
console.log 'App started'
console.log "Listening on port: #{port}"
# routes/index.ls
'use strict'
module.exports =
'/': (req, res) ->
res.send "Hello World"
I realize theres been no code committed into this repo in the last couple of years. I really loved the way routescan handles the routes. I am just curios, if the routescan automatically picks up the folder name and adds it as a context to the routes defined in it? For example?
If the routes in routes/user.js are defined as '/signup' and '/signin'.... this will be treated as http://server/signup and http://server/signin ....... if the file user.js is put inside the folder security.... i.e. routes/security/user.js .... the new routes should automatically be http://server/security/signup and http://server/security/signin. The folder in which the route is defined gets treated as part of the route and sets the context to the routes.
For example: https://github.com/stonecircle/express-autoroute does this part of it... I just like routescan in terms of everything else... :)
I haven't reviewed all of your code, can you please tell me if pass the next parameter to all routes. I need it for handling errors.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.