Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lots of if-elses #49

Open
morkeltry opened this issue Dec 8, 2017 · 1 comment
Open

Lots of if-elses #49

morkeltry opened this issue Dec 8, 2017 · 1 comment

Comments

@morkeltry
Copy link

morkeltry commented Dec 8, 2017

in router.js.
The alternative would be to first test for existence or non-existence in a whitelist, eg as an array.
Then a case statement would be neater than if-elses.
Even more elegant than case would be designing the whitelist array keyed by route, including actions to take,
eg

whitelistedActions=   {
  '/' : handlers.homeHandler,
  '/home': handler.everyoneGoHome,
  '/loadcomments': getComments
}
...
whitelistedActions[endpoint] (req, res, endpoint);

or

whitelist= {
 '/': ['index.html','text/html'],
 'favicon.ico': ['/images/favicon.ico','image/png'],
 'script.js': ['/views/frontendscript.js','application/javascript']
};
...
staticFileHandler (req,res, whitelist [endpoint]);

or, in your case, a combination of parts of the two with logic..

}

@shannonjensen
Copy link
Collaborator

ooh, thank you for the suggestion...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants