0

I'm building a shopping cart project using Node, Express, handlebars and MongoDB. Currently, when I attempt to submit a form, using Jquery, I receive a 404 error for my '/checkout' file. Originally, I used return false to prevent the form from submitting before it receives the data. In an attempt to fix the issue, I tried using event.preventDefault, as well. On another forum, someone suggested that my crsf protection is not creating the token properly. I worked with the route and added to my view and finally the hbs form. None of these attempts appear to have solved my issue.

This is a link to my gist. https://gist.github.com/Satellite9/5e4ce3de5c19cee2f355d872b6d7d3c8

This is the error that my browser sends me.

*Error: Not Found at C:\Users\Leimamo\PhpstormProjects\untitled2\app.js:60:13 at Layer.handle [as handle_request] (C:\Users\Leimamo\PhpstormProjects\untitled2\node_modules\express\lib\router\layer.js:95:5) at trim_prefix (C:\Users\Leimamo\PhpstormProjects\untitled2\node_modules\express\lib\router\index.js:317:13) at C:\Users\Leimamo\PhpstormProjects\untitled2\node_modules\express\lib\router\index.js:284:7 at Function.process_params (C:\Users\Leimamo\PhpstormProjects\untitled2\node_modules\express\lib\router\index.js:335:12) at next (C:\Users\Leimamo\PhpstormProjects\untitled2\node_modules\express\lib\router\index.js:275:10) at C:\Users\Leimamo\PhpstormProjects\untitled2\node_modules\express\lib\router\index.js:635:15 at next (C:\Users\Leimamo\PhpstormProjects\untitled2\node_modules\express\lib\router\index.js:260:14) at Function.handle (C:\Users\Leimamo\PhpstormProjects\untitled2\node_modules\express\lib\router\index.js:174:3) at router (C:\Users\Leimamo\PhpstormProjects\untitled2\node_modules\express\lib\router\index.js:47:12) at Layer.handle [as handle_request] (C:\Users\Leimamo\PhpstormProjects\untitled2\node_modules\express\lib\router\layer.js:95:5) at trim_prefix (C:\Users\Leimamo\PhpstormProjects\untitled2\node_modules\express\lib\router\index.js:317:13) at C:\Users\Leimamo\PhpstormProjects\untitled2\node_modules\express\lib\router\index.js:284:7 at Function.process_params (C:\Users\Leimamo\PhpstormProjects\untitled2\node_modules\express\lib\router\index.js:335:12) at next (C:\Users\Leimamo\PhpstormProjects\untitled2\node_modules\express\lib\router\index.js:275:10) at C:\Users\Leimamo\PhpstormProjects\untitled2\app.js:51:5 at Layer.handle [as handle_request] (C:\Users\Leimamo\PhpstormProjects\untitled2\node_modules\express\lib\router\layer.js:95:5) at trim_prefix (C:\Users\Leimamo\PhpstormProjects\untitled2\node_modules\express\lib\router\index.js:317:13) at C:\Users\Leimamo\PhpstormProjects\untitled2\node_modules\express\lib\router\index.js:284:7 at Function.process_params (C:\Users\Leimamo\PhpstormProjects\untitled2\node_modules\express\lib\router\index.js:335:12) at next (C:\Users\Leimamo\PhpstormProjects\untitled2\node_modules\express\lib\router\index.js:275:10) at serveStatic (C:\Users\Leimamo\PhpstormProjects\untitled2\node_modules\serve-static\index.js:75:16) at Layer.handle [as handle_request] (C:\Users\Leimamo\PhpstormProjects\untitled2\node_modules\express\lib\router\layer.js:95:5) at trim_prefix (C:\Users\Leimamo\PhpstormProjects\untitled2\node_modules\express\lib\router\index.js:317:13) at C:\Users\Leimamo\PhpstormProjects\untitled2\node_modules\express\lib\router\index.js:284:7 at Function.process_params (C:\Users\Leimamo\PhpstormProjects\untitled2\node_modules\express\lib\router\index.js:335:12) at next (C:\Users\Leimamo\PhpstormProjects\untitled2\node_modules\express\lib\router\index.js:275:10) at SessionStrategy.strategy.pass (C:\Users\Leimamo\PhpstormProjects\untitled2\node_modules\passport\lib\middleware\authenticate.js:325:9) *

this is the error that npm gives me Post /checkout 404 206.855 ms -5424

Thank you for any insight you may have.

Killeon

Dinesh undefined
  • 5,490
  • 2
  • 19
  • 40

2 Answers2

1

you are using wrong verb on index.js. change get->post.

router.get('/checkout', function(req, res, next) {
......
});

to

router.post('/checkout', function(req, res, next) {
....
});
Fazal Rasel
  • 4,446
  • 2
  • 20
  • 31
  • Hi Fazal, when I change the verb from router.get to router.post, I get a 404 error for the route 'POST /shop/checkout 404'. Thank you for your reply. – Killeon Jerrod Jun 19 '17 at 07:09
  • I tried a few different ways; changed the route to router.post '/shop/checkout' and still, the error returned a failed search for '/checkout'. – Killeon Jerrod Jun 19 '17 at 08:24
0

Edit with my demo, man.

router.get('/checkout', function(req, res, next) {
 //do something
    });

router.post('/checkout', function(req, res, next) {
// do something: get params with req.body
    });

I worked with the route and added to my view and finally the hbs form

hbs form: I use route with post when submit form

Alex
  • 3,646
  • 1
  • 28
  • 25
  • Hi Anhlee, I'm not sure that I follow your suggestion. Are you saying that the verb is incorrect, as well? Thank you for responding. – Killeon Jerrod Jun 19 '17 at 08:00