Next.js: Receiving post requests is not implemeneted

Created on 31 Jul 2018  路  7Comments  路  Source: vercel/next.js

I created simple form element on my website. It looked like this:
<form method="post"> <input name="firstname"/> <input name="lastname"/> <input type="submit"/> </form>
After pressing submit button I got 501 with text

Not Implemented

Most helpful comment

@timneutkens I think it's a valid question. I compiled my app that has client and server. Client basically has pages so it's a frontend. And server is custom express server. I created build with next build ./client and then started with next start ./client. The server runs fine. Now, I have a login page and accepts email and password. I try to submit login form and it returns 501 - Not Implemented while I was expecting it to work with next build. Perhaps there's still something I don't get. Can you please let me know what could be missing? How can deploy my app to production with my current setup.

All 7 comments

Next.js only handles rendering, if you want to handle data coming into the app you have to implement your own routes for that using a custom server

I have the same issue, but my problem is when I run nextjs with prod with npm run build;npm run start and my form into onSubmit function use a function ajax for send data to my api server, the page shows "Not Implement", but not is always only in few cases <Form name="PasswordRestoreForm" method="POST" onSubmit={handleSubmit(values =>{restorePass(values);})}> <Field label="Correo electr贸nico" name="email" placeholder="Correo electr贸nico" disabled={sendIn} component={TextField} validate={[Validations.email, Validations.required]} /> <div className="divider" /> <SubmitButton className="button-lg btn-main" style={{width: '100%'}} disabled={sendIn} text={sendIn ? 'Enviando' : 'Enviar'} /> </Form>

You probably have to add event.preventDefault()

@timneutkens I am using Redux Forms and with "handleSubmit" does call to "preventDefault" default

@timneutkens I think it's a valid question. I compiled my app that has client and server. Client basically has pages so it's a frontend. And server is custom express server. I created build with next build ./client and then started with next start ./client. The server runs fine. Now, I have a login page and accepts email and password. I try to submit login form and it returns 501 - Not Implemented while I was expecting it to work with next build. Perhaps there's still something I don't get. Can you please let me know what could be missing? How can deploy my app to production with my current setup.

I think this issue should be changed to a feature request. I want it too but this test would suggest that it's intentionally not supported:

https://github.com/zeit/next.js/blob/14eef587025a0fa28cbb24f2aa8e2829209ae9b2/test/integration/production/test/index.test.js#L80

btw two things are being conflated above:

  1. Doing an ajax post to a RESTful endpoint without reloading the page
  2. A more traditional form post that would reload the page. the event.preventDefault() suggestion is what you'd need to hijack the traditional form post action and submit using javascript without a page reload.

For option 2, triggering a form post to a next.js page should be possible but apparently is not (yet). I guess I'll build a web service as a workaround (option 1)

Was this page helpful?
0 / 5 - 0 ratings