Is OpenLiteSpeed blocking my proxy server

#1
Hi everyone

I'm very new to OpenLiteSpeed. Having paid for a reseller hosting for many years I have decided to try a different method.

I have purchased a server from Hetzner and proceeded to install CyberPanel with OpenLiteSpeed. This appears to work perfectly fine but I'm having an issue with my proxy server I have created.

Basically, I want to have a form on my site that sends data to my Airtable Database and therefor created a server.js file that hides my api credentials. Without Cyberpanel and OpenLiteSpeed it was working fine but as soon as I install them, when I click the submit button on my form, I can no longer connect.

I've used node.js to create the proxy server which uses Express, axis, https, fs and cors. The server.js is located in the root/airtable-proxy and the form is located in the public_html folder.

I have a feeling it's OpenLiteSpeed that is stopping this but I can't workout how to allow it to work. I've been searching online for a few days and I am stuck and need help. I've tried creating a virtual host and adding all the data so if that is the correct way, I am inputting the data wrong and I need a little guidance.

Thanks
 
#3
Hi

To be honest, learning how to do the proxy, switching over to my own server and now configuring OpenLiteSpeed in a short space has left me a little confused.

Here is my files:

index.html (located in the public_html folder)
Code:
<!DOCTYPE html>
<html>
<head>
  <title>Airtable Form</title>
</head>
<body>
  <form id="airtableForm">
    <label for="name">Name:</label>
    <input type="text" id="name" name="name"><br><br>

    <label for="age">Age:</label>
    <input type="number" id="age" name="age"><br><br>

    <label for="email">Email:</label>
    <input type="email" id="email" name="email"><br><br>

    <label for="amount">Amount:</label>
    <input type="number" id="amount" name="amount"><br><br>

    <label for="postcode">Postcode:</label>
    <input type="text" id="postcode" name="postcode"><br><br>

    <input type="submit" value="Submit">
  </form>

  <script>
    document.getElementById('airtableForm').addEventListener('submit', function(event) {
      event.preventDefault(); // Prevent the default form submission
 
      // Collect form data
      const formData = {
        name: document.getElementById('name').value,
        age: parseInt(document.getElementById('age').value),
        email: document.getElementById('email').value,
        amount: parseFloat(document.getElementById('amount').value),
        postcode: document.getElementById('postcode').value
      };

      fetch('https://mydomain.co.uk:5000/submit', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json'
        },
        body: JSON.stringify(formData)
      })
      .then(response => response.json())
      .then(data => {
        alert(data.message); // Display the server's response message
        document.getElementById('airtableForm').reset();
      })
      .catch(error => {
        alert('Error posting to Airtable:'); // Display the error message
      });
    });
  </script>
 
</body>
</html>
server.js (located in root/airtable-proxy)
Code:
const express = require('express');
const axios = require('axios');
const https = require('https');
const fs = require('fs');
const cors = require('cors');
require('dotenv').config();

const app = express();

// Use cors middleware
const corsOptions = {
  origin: 'https://mydomain.co.uk',
  optionsSuccessStatus: 200 // For legacy browser support
};

app.use(cors(corsOptions));

app.use(express.json());

app.post('/submit', async (req, res) => {
  const { name, age, email, amount, postcode } = req.body;

  // Prepare Airtable API request
  const airtableData = {
    records: [
      {
        fields: {
          Name: name,
          Age: age,
          Email: email,
          Amount: amount,
          Postcode: postcode
        }
      }
    ]
  };

  try {
    await axios.post(
      `https://api.airtable.com/v0/${process.env.AIRTABLE_BASE_ID}/${process.env.AIRTABLE_TABLE_ID}`,
      airtableData,
      {
        headers: {
          'Authorization': `Bearer ${process.env.AIRTABLE_API_KEY}`,
          'Content-Type': 'application/json'
        }
      }
    );
    res.json({ message: "Form posted to Airtable" }); // Sending success message
  } catch (error) {
    console.error('Error posting to Airtable:', error);
    res.status(500).json({ message: "Error posting to Airtable:" }); // Sending error message
  }
});

const privateKey = fs.readFileSync('../../etc/letsencrypt/live/mydomain.co.uk/privkey.pem', 'utf8');
const certificate = fs.readFileSync('../../etc/letsencrypt/live/mydomain.co.uk/cert.pem', 'utf8');
// If you have a certificate authority file, use the following line. Otherwise, you can comment or remove it.
// const ca = fs.readFileSync('path/to/ca.crt', 'utf8');

const credentials = {
  key: privateKey,
  cert: certificate,
  // ca: ca // Optional, only if you have a certificate authority file
};

const PORT = process.env.PORT || 5000;
const httpsServer = https.createServer(credentials, app);

httpsServer.listen(PORT, () => {
  console.log(`HTTPS Server running on port ${PORT}`);
});
I then have a doting file located in root/airtable-proxy with the api credentials.

I'll be honest, I've looked at the link you provided and I now have brain freeze.

Thanks
 

Cold-Egg

Administrator
#4
Hi,

So the form is loading ok, but it does not fetch the backend at port 5000 for some reason? If you send a request from SSH console directly(no OLS and CyberPanel involved), will that work?
 
#5
Hi

Yes, the form loads ok but I get the error in the inspector when you click send.

I’m not sure how to send the request directly from an ssh console?
 

Cold-Egg

Administrator
#6
Hi @Derby5341

Without Cyberpanel and OpenLiteSpeed it was working fine but as soon as I install them, when I click the submit button on my form, I can no longer connect.
May I know, how you tested it before, when there's no OLS installed?

And what's the error code in your inspector?
 
Top