Skip to content

Use res.status() #576

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

Closed
kingcody opened this issue Sep 21, 2014 · 19 comments
Closed

Use res.status() #576

kingcody opened this issue Sep 21, 2014 · 19 comments

Comments

@kingcody
Copy link
Member

As pointed out by @eikaramba, Express 4 now uses a syntax such as:

res.status(200).send('My Page');
res.status(201).json({token: token});

This should be implemented in the server code and endpoint template.

@gintsgints
Copy link
Contributor

I would like to make necesary changes. Sadly I cannot make fork on github. It always make me to generator-angular fork. So I start with local clone.

@JaKXz
Copy link
Collaborator

JaKXz commented Sep 25, 2014

Whoops misclicks. Looking forward to the PR @gintsgints 😄

@gintsgints
Copy link
Contributor

Can you please point me on instructions how to make PR from local clone?
Or somehow I can fix issue on creating wrong fork.

@kingcody
Copy link
Member Author

@gintsgints you'll need to have a fork on github to be able to push new beaches to. Once a new branch is pushed to github you'll see a button on your project's main page to create a PR.

We'll need to get you a proper fork before you can make a PR.

I'm guessing you've tried clicking the fork button on the main page for this project?

@JaKXz
Copy link
Collaborator

JaKXz commented Sep 25, 2014

I believe you can still make PRs with a local clone. Just push to your topic branch as usual (e.g. origin/fix-res-status) and then you'll have to manually do the compare in GitHub:

https://github.com/gintsgints/generator-angular-fullstack/compare/DaftMonk:master...fix-res-status

Or, you could give git-extras a shot, see if the git fork command works. It's a great library. 😄

@kingcody
Copy link
Member Author

Perhaps I'm missing something but if @gintsgints simply cloned this repo then his origin would be this repo by default. He would need to create a new project on github and then add it as a remote. Then he could push to it and maybe(?) make a PR.

@JaKXz
Copy link
Collaborator

JaKXz commented Sep 25, 2014

@kingcody yup, sorry I left out the [implicit] steps of replacing the origin remote.

@gintsgints
Copy link
Contributor

This way, I managed to create repository at github that is actual clone of generator-angular-fullstack. But it now do not want to allow to create PR from two "different" repos :(

@kingcody
Copy link
Member Author

@gintsgints I've made a branch containing the changes for this issue. I was wondering if you would like to review it or possibly submit your own PR. Either way thanks for all your help on the project :)

@gintsgints
Copy link
Contributor

First difference I found is I use:

return res.status(204);

yours

return res.status(204).end();

I do not know is end() needed or not but it worked for me without.

@gintsgints
Copy link
Contributor

Also do not know what could be better:

res.json(users);

vs

res.status(200).json(users);

probably first :)

@kingcody
Copy link
Member Author

@gintsgints as for .end() see here (:

@gintsgints
Copy link
Contributor

@kingcody agreed on .end() 👍

kingcody added a commit to kingcody/generator-angular-fullstack that referenced this issue Sep 26, 2014
Changes:
- use `res.status()` instead of `res.verb(123, item)`

Closes angular-fullstack#576
@kingcody
Copy link
Member Author

Thanks @gintsgints, I appreciate the extra set of eyes on this.

@gintsgints
Copy link
Contributor

What else... I had different files for modification. (IMHO I have modified master).

@gintsgints
Copy link
Contributor

Mean yours and mine templates name.controller.js was different.
Mine had fragment like this:

<%= classedName %>.findById(req.params.id, function (err, <%= name %>) {
     if (err) { return handleError(res, err); }
-    if(!<%= name %>) { return res.send(404); }
+    if(!<%= name %>) { return res.state(404); }
     var updated = _.merge(<%= name %>, req.body);
     updated.save(function (err) {
       if (err) { return handleError(res, err); }
-      return res.json(200, <%= name %>);
+      return res.state(200).json(<%= name %>);

@kingcody
Copy link
Member Author

I did have a typo in name.controller.js it should be fixed in the most recent push.

@JaKXz
Copy link
Collaborator

JaKXz commented Dec 6, 2014

I think this was taken care of in #704, correct me if I'm wrong.

@JaKXz JaKXz closed this as completed Dec 6, 2014
@gintsgints
Copy link
Contributor

Yes. All done.
2014. gada 6. dec. 20:12, "Jason Kurian" [email protected]
rakstīja:

I think this was taken care of in #704
#704,
correct me if I'm wrong.


Reply to this email directly or view it on GitHub
#576 (comment)
.

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

No branches or pull requests

3 participants