Telos8840
Telos8840

Reputation: 33

Heroku + Node + Express Route not found after deploy

After deploying my app to Heroku, it no longer can find the API path I have setup in Express. This code works totally fine locally but once its in Heroku, I get a 404 - Page Not Found error.

This is the router:

const router      = require('express').Router(),
form    = require('../api/form');

router.post('/api/submit', (req, res) => {
    form.submit(req, res);
});

module.exports = router;

And its being submitted via a jQuery POST

$('form').on('submit', function(e) {
    e.preventDefault();
    $.post('/api/submit', $('form').serialize(), function (data) {
        $('#confirm-modal').modal('show');
    });
});

I don't see any errors in Herokus logs either. I could see in the logs that it is hitting "/api/submit" but nothing happens.

What's even more strange is I've used all this exact same code in another project and it works fine ¯_(ツ)_/¯

Any help would be greatly appreciated as I've run out of ideas.

Upvotes: 2

Views: 1596

Answers (1)

Telos8840
Telos8840

Reputation: 33

I ended up just moving it from "/api/submit" to "/submit" and now it suddenly works. Not sure why that's the case but it fixed this issue.

Upvotes: 1

Related Questions