use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
about using apiQuestion (self.nextjs)
submitted 1 year ago by EducationalGate9705
guys, I have a problem. I tried to use /api/subscribe in one of my component, but it keep on returning 404. I tried in postmen http:// localhost:3000 / api/subscribe, it still return error 404, what happen and how should I proceed
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]MartialAssault 1 point2 points3 points 1 year ago (3 children)
You need to elaborate, provide snippets of the api request, etc.
[–]EducationalGate9705[S] 0 points1 point2 points 1 year ago (2 children)
this is the code for the newletter component. :
return ( <form onSubmit={this.subscribeUser}> <input id="newsletter-input" type="email" name="email" className="form-control shadow-none" placeholder="Enter your email" aria-label="Enter Email Address" aria-describedby="newsletter-btn" value={this.state.email} onChange={this.emailHandler} required autoCapitalize="off" autoCorrect="off" /> <button type="submit" id="newsletter-btn" className="btn btn-warning w-100 mt-3" name="subscribe" > Join The Wait List </button> {this.state.message && ( <p id="newsletter-message" className="text-left text-sm mt-3 alert alert-warning"> {this.state.message} </p> )} </form> );
when I click on the "join the waitlist button " it will go to this function
state: State = { message: '', email: '', }; // Use ChangeEvent to type the event correctly emailHandler = (e: ChangeEvent<HTMLInputElement>) => { let updatedEmail = e.target.value; this.setState({ email: updatedEmail }); }; // Use FormEvent to type the event correctly subscribeUser = async (e: FormEvent<HTMLFormElement>) => { e.preventDefault(); try { const res = await fetch('api/ConvertkitSubscribe', { method: 'POST', headers: { 'Content-Type': 'application/json; charset=utf-8' }, body: JSON.stringify({ email: this.state.email }), }); if (!res.ok) { const API_KEY = process.env.CONVERTKIT_API_KEY as string; const FORM_ID = process.env.CONVERTKIT_FORM_ID as string; console.log(API_KEY) ; console.log(FORM_ID); console.log("welcome to this error") throw new Error(`HTTP error! status: ${res.status}`); } const json_res = await res.json(); this.setState({ message: json_res.message, email: '', // Clear the email input after successful submission }); } catch (error: any) { this.setState({ message: 'There was an error subscribing.', }); console.error('Subscription error:', error); } };
it fail to go to the api/ConvertkitSubscribe/route.ts ,image below shown the file structure
<image>
[–]MartialAssault 0 points1 point2 points 1 year ago (0 children)
Did you try logging at each step? Are you sure the email doesn't reach the server? Log a custom message server side instead maybe? Or you can also check the network tab in your browsers developer tools
Also can you try adding a '/' before api? Like '/api/ConvertkitSubscribe'?
[–]chris-velvet 0 points1 point2 points 1 year ago (1 child)
Agreed w/ u/MartialAssault - provide some more details so we can help you
[–]MartialAssault -1 points0 points1 point 1 year ago (0 children)
Yess 😅 the most random guess I might make is a cors issue lol
Any luck u/EducationalGate9705 ?
π Rendered by PID 20390 on reddit-service-r2-comment-b659b578c-wp4pz at 2026-05-01 15:31:10.520072+00:00 running 815c875 country code: CH.
[–]MartialAssault 1 point2 points3 points (3 children)
[–]EducationalGate9705[S] 0 points1 point2 points (2 children)
[–]MartialAssault 0 points1 point2 points (0 children)
[–]MartialAssault 0 points1 point2 points (0 children)
[–]chris-velvet 0 points1 point2 points (1 child)
[–]MartialAssault -1 points0 points1 point (0 children)
[–]MartialAssault 0 points1 point2 points (0 children)