Wednesday 24 May 2017

Heroku: POST Error 414 (Request-URI Too Long)

SITUATION:

My SPA works fine on my local machine. But when uploaded to Heroku, it gives me a 414 error when I try to create a Poll.

What is causing this and how do I fix it ?


LIVE:

Here is the SPA live: https://voting-app-10.herokuapp.com/polls

Just create any dummy account with fake info and try creating a poll. You'll get the error in the console.


PROJECT CODE:

Here is the project code: https://www.dropbox.com/s/6eop089d2dehm7p/Voting%20App.zip?dl=0

Here is the POST code for the creation of a poll:


CODE:

addPoll(poll: Poll) {
        const body = JSON.stringify(poll);
        const headers = new Headers({'Content-Type': 'application/json'});
        const token = localStorage.getItem('token')
            ? '?token=' + localStorage.getItem('token')
            : '';
        return this.http.post('http://localhost:3000/poll' + token, body, {headers: headers})
            .map((response: Response) => {
                const result = response.json();
                const poll = new Poll(
                    result.obj.title,
                    result.obj.choice1,
                    result.obj.choice2,
                    0,
                    0,
                    result.obj.user.firstName,
                    result.obj._id,
                    result.obj.user._id,
                    );
                this.polls.unshift(poll);
                return poll;
            })
            .catch((error: Response) => {
                this.errorService.handleError(error.json());
                return Observable.throw(error);
            });
    }



via Coder1000

No comments:

Post a Comment