skip to Main Content

I don’t know how to make the code showable to the client after the client submit the form and don’t know also how to make the client submit more than one (multiply times) i want it like this:

---the form---
input 
input 
input
submit button

--here show the response--

and the client able to send multiply submits and the response show as above.
also it give me this error:

/home/runner/costalica/index.js:87
      })
        

SyntaxError: Unexpected end of input

Here is my code:

const fetch = require('node-fetch');
const express = require('express');
const app = express();

// Parse request bodies
app.use(express.json());
app.use(express.urlencoded({
  extended: true
}));
app.listen(3000);
app.get('/', (request, response) => {
  let responseHTML = `
    <html>
      <body>
        <h1>Login Form</h1>
        <form method="POST" action="/">
          <label for="csrf_token">CSRF Token:</label> 
          <input type="text" name="csrf_token" id="csrf_token"><br>   
          
          <label for="email">Email:</label>  
          <input type="email" name="email" id="email"><br>
          
          <label for="password">Password:</label>  
          <input type="password" name="password" id="password"><br>
          
          <input type="submit" value="Submit">
        </form>
      </body>
    </html>
  `
  response.send(responseHTML)
})

app.post('/', (req, res) => {
      const {
        csrf_token,
        email,
        password
      } = req.body;

      const data = `{
    "_csrf_token": "${csrf_token}", 
    "email": "${email}", 
    "grant_type": "PWD", 
    "page": "AccountLogin", 
    "password": "${password}",
    "recaptchaResponse": null, 
    "recaptchaSiteKey": null, 
    "step": "password",
    "userDefaultedToPassword": false 
  }`;

      let reqq = fetch('https://scrapeninja.p.rapidapi.com/scrape', {
        method: 'POST',
        headers: {
          "Content-Type": "application/json",
          "x-rapidapi-host": "HIDDEN",
          "x-rapidapi-key": "HIDDEN"
        },
        body: JSON.stringify({
          "url": "https://www.wayfair.com/a/account/authentication/login",
          "method": "POST",
          "headers": [
            "authority: www.wayfair.com",
            "accept: application/json",
            "accept-language: en-US,en;q=0.9,ar;q=0.8",
            "content-type: application/json",
            "cookie: WFDC=DSM; CSNUtId=412864fc-a9f8-405c-8e19-aa56c086d7ea; ExCSNUtId=412864fc-a9f8-405c-8e19-aa56c086d7ea; vid=23e17d3a-64a8-81d9-9e3c-5c0227712302; SFSID=ed904601ed2bb197bcbf8d4f7643e8cc; canary=0; serverUAInfo=%7B%22browser%22%3A%22Google%20Chrome%22%2C%22browserVersion%22%3A114%2C%22OS%22%3A%22Windows%22%2C%22OSVersion%22%3A%2210%22%2C%22isMobile%22%3Afalse%2C%22isTablet%22%3Afalse%2C%22isTouch%22%3Afalse%7D; __px_jnfwwtr_5=disable; _pxhd=bytlkNG5QrgGWPC-1RImOXynN/cLl26bEP24UXFCHXT4He3u0Wh/mg3ui2mytf2n27lyNOZ85vc-lS7T36UIWw==:eLUfj4aK5RXvvmjDlAlCh8zSBU-3GpStZIT2o40y1HojI1D3p7xCH/aXJfZGO9TizTXeUiEBw5yVXmJFLaHL8fQYbI6z3V8rtEWJuu6zneo=; CSN_CSRF=c60cafb9043d3d61febb81a38d23ece011ecf59df63774332d8a1be0c401fe52; __cf_bm=OYuVFxcPmLDoUgBGpP7Nj78NQm5R.Jr7cK8ggEIR3Wo-1688764889-0-AejgIZQcufTBjfmr47Oi/soHVUy7JtWjQ0r9cSXFy8T+Rznig68CKCwIFVNcjBEv3llV7a66LjzOq8HiB9IQIac=; CSN=g_countryCode%3DUS%26g_zip%3D67346; CSNPersist=page_of_visit%3D5; _wf_fs_sample_user=true; ibb=1; CSNID=FCD55A66-8513-46C7-A656-C2C65BB20149; WFCS=CS9; g_state={"i_p":1688772129177,"i_l":1}; hideGoogleYolo=true",
            "origin: https://www.wayfair.com",
            "referer: https://www.wayfair.com/v/account/authentication/login?url=https%3A%2F%2Fwww.wayfair.com%2F&context=header_wayfair_my_account_menu",
            "sec-ch-ua: "Not.A/Brand";v="8", "Chromium";v="114", "Microsoft Edge";v="114"",
            "sec-ch-ua-mobile: ?0",
            "sec-ch-ua-platform: "Windows"",
            "sec-fetch-dest: empty",
            "sec-fetch-mode: cors",
            "sec-fetch-site: same-origin",
            "sec-gpc: 1",
            "user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1823.67",
            "x-auth-caller-context: auth_main_page_context",
            "x-csn-csrf-token: c60cafb9043d3d61febb81a38d23ece011ecf59df63774332d8a1be0c401fe52",
            "x-parent-txid: I+F9OmSoge50vzFQLI6HAg==",
            "x-requested-with: XMLHttpRequest"
          ],
          "data": data
        })
      });
      reqq.then(res => {
        const json = res.json();
        responseHTML += `<pre>${JSON.stringify(json, null, 2)}</pre>`
      })

2

Answers


  1. const fetch = require('node-fetch');
    const express = require('express');
    const app = express();
    
    // Parse request bodies
    app.use(express.json());
    app.use(express.urlencoded({ extended: true }));
    app.listen(3000);
    
    let submissions = []; // Array to store form submissions
    
    app.get('/', (request, response) => {
      let responseHTML = `
        <html>
          <body>
            <h1>Login Form</h1>
            <form method="POST" action="/">
              <label for="csrf_token">CSRF Token:</label>
              <input type="text" name="csrf_token" id="csrf_token"><br>
    
              <label for="email">Email:</label>
              <input type="email" name="email" id="email"><br>
    
              <label for="password">Password:</label>
              <input type="password" name="password" id="password"><br>
    
              <input type="submit" value="Submit">
            </form>
    
            <h2>Responses:</h2>
            <ul>
              ${submissions.map((submission) => `<li>${submission}</li>`).join('')}
            </ul>
          </body>
        </html>
      `;
      response.send(responseHTML);
    });
    
    app.post('/', (req, res) => {
      const { csrf_token, email, password } = req.body;
      const responseText = `CSRF Token: ${csrf_token}, Email: ${email}, Password: ${password}`;
      submissions.push(responseText);
      res.redirect('/');
    });
    
    Login or Signup to reply.
  2. Your app.post are missing brackets all over the place.

    You can find which, by removing objects that are self contained until you have the correct structure. For example

    app.post('/', (req, res) => {
      const {
        csrf_token,
        email,
        password
      } = req.body;
    
    
      fetch('https://scrapeninja.p.rapidapi.com/scrape', { // no need to save 
        method: 'POST',
        headers: {
          "Content-Type": "application/json",
          "x-rapidapi-host": "HIDDEN",
          "x-rapidapi-key": "HIDDEN"
        },
        body: JSON.stringify({
          "url": "https://www.wayfair.com/a/account/authentication/login",
          "method": "POST",
          "headers": [......]
        }), // added
        "data": data
      }).then(res => { // added the then to the fetch
        const json = res.json();
        responseHTML += `<pre>${JSON.stringify(json, null, 2)}</pre>`
      })
    })
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search