#404 not found

3 messages · Page 1 of 1 (latest)

elfin harbor
#

create-server.js(src/pages/api)

export async function post({ request }) {
    const formData = await request.formData();
    const userData = Object.fromEntries(formData);
    // Logik untuk mengirim data ke Pterodactyl API
    try {
      const PTERODACTYL_HOST = 'panel';
      const API_KEY = 'token';
      const response = await fetch(`${PTERODACTYL_HOST}/api/application/users`, {
        method: 'POST',
        headers: {
          'Authorization': `Bearer ${API_KEY}`,
          'Content-Type': 'application/json',
          'Accept': 'Application/vnd.pterodactyl.v1+json',
        },
        body: JSON.stringify({
          // Struktur data sesuai kebutuhan API
          ...userData,
          external_id: null,
          root_admin: false,
        }),
      });
      if (!response.ok) {
        throw new Error(`Error: ${response.status}`);
      }
      return new Response('User created successfully', { status: 200 });
    } catch (error) {
      return new Response(`Failed to create user: ${error.message}`, { status: 500 });
    }
  }

components

---
// Import statement jika diperlukan
---
<form method="POST" action="/api/create-user">
    <input type="text" name="username" placeholder="Username" required /><br />
    <input type="email" name="email" placeholder="Email" required /><br />
    <input type="text" name="firstName" placeholder="First Name" required /><br />
    <input type="text" name="lastName" placeholder="Last Name" required /><br />
    <input type="password" name="password" placeholder="Password" required /><br />
    <button type="submit">Submit</button>
  </form>
rain pierBOT
#

Hi @elfin harbor. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Hmm, I don't know enough to give you a confident answer yet. The code you provided seems to be related to a Pterodactyl API and not directly related to Astro. However, if you're trying to create server endpoints in Astro, you might find the following guides helpful:

These guides provide examples of how to create server endpoints and forms in Astro. If you're encountering a 404 error, it might be because the server endpoint you're trying to reach doesn't exist or isn't correctly set up. Please ensure that your server endpoint is correctly defined and matches the action URL in your form.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: