This repository has been archived by the owner. It is now read-only.
Null basket server #2485
Merged
Null basket server #2485
Conversation
|
This just-proxy-it-to-basket business is turning out to be a lot more work than I was hoping we'd get away with...@zaach @shane-tomlinson @vladikoff I salute your commitment to not shipping code that hasn't been properly tested. |
| function initApp() { | ||
| var app = express(); | ||
| app.use(bodyParser.json()); | ||
| app.use(verifyApiKey()); |
shane-tomlinson
May 28, 2015
Member
verifyApiKey is the actual middleware, no need for the ()
verifyApiKey is the actual middleware, no need for the ()
| userData[email] = { | ||
| email: email, | ||
| token: token, | ||
| newsletters: params.newsletters.slipt(',') |
shane-tomlinson
May 28, 2015
Member
slipt=>split.
slipt=>split.
|
|
||
| app.post('/unsubscribe/:token/', function (req, res) { | ||
| var user = tokenToUser[req.body.token]; | ||
| var newsletters = req.params.newsletters.slit(','); |
shane-tomlinson
May 28, 2015
Member
slit=>split
slit=>split
|
|
||
| function initApp() { | ||
| var app = express(); | ||
| app.use(bodyParser.json()); |
| } else { | ||
| user.newsletters = user.newsletters.concat(params.newsletters.split(',')); | ||
| } | ||
| res.send(200, { status: 'ok' }); |
shane-tomlinson
May 28, 2015
Member
Express says this form is deprecated:
express deprecated res.send(status, body): Use res.status(status).send(body) instead null-basket-server.js:102:9
Express says this form is deprecated:
express deprecated res.send(status, body): Use res.status(status).send(body) instead null-basket-server.js:102:9
| app.get('/lookup-user/', function (req, res) { | ||
| var email = req.params.email; | ||
| if (! userData[email]) { | ||
| res.status(400).json(errorResponse('unknown-email', BASKET_ERRORS.UNKNOWN_EMAIL)); |
| res.status(400).json(errorResponse('unknown-email', BASKET_ERRORS.UNKNOWN_EMAIL)); | ||
| return; | ||
| } | ||
| res.json(userData[email]); |
shane-tomlinson
May 28, 2015
Member
This also needs to send a status: "ok" as part of the returned data.
This also needs to send a status: "ok" as part of the returned data.
| app.use(verifyApiKey); | ||
|
|
||
| app.get('/lookup-user/', function (req, res) { | ||
| var email = req.params.email; |
shane-tomlinson
May 28, 2015
Member
email comes over query parameters, use req.query here.
email comes over query parameters, use req.query here.
| }); | ||
|
|
||
| app.post('/unsubscribe/:token/', function (req, res) { | ||
| var user = tokenToUser[req.body.token]; |
shane-tomlinson
May 28, 2015
Member
the token comes from req.params, the newsletters from req.body.
the token comes from req.params, the newsletters from req.body.
* `verifyApiKey` is already middleware, do not make a function call when setting it up as middleware. * Fetch the parameters from the right place.
| } | ||
|
|
||
| return target; | ||
| } |
pdehaan
May 28, 2015
Contributor
Curious, but why not just something like Underscore's _.extend()?
Curious, but why not just something like Underscore's _.extend()?
shane-tomlinson
May 28, 2015
Member
underscore isn't an npm dependency, and I thought since it was just a single function that I need, I'll just hack it in.
underscore isn't an npm dependency, and I thought since it was just a single function that I need, I'll just hack it in.
zaach
May 28, 2015
Author
Contributor
👍
zaach
added a commit
that referenced
this pull request
May 28, 2015
tests(basket): Null basket server r=shane-tomlinson
Merged
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
WIP, untested
Will help us test and develop locally. Meant to be a minimal copy of the Basket API.
/cc @shane-tomlinson