CORS blocking POST request

Website URL

mysql1.free.nf
URL sending requests: https://zxcvbnm.ipse.ro.

Error Message

(Sorry have to replace links with text it will only let me make 2 links.)
Error message on external url sending requests: Access to fetch at ‘infinity free url’ from origin ‘external url’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. If an opaque response serves your needs, set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.

Other Information

Hello! I have a website with a search bar and I am trying to see what users search. Here is my allow CORS script on my mysql1.free.nf site:

const express = require('express');
const cors = require('cors');

const app = express();

// Define CORS options
const corsOptions = {
  origin: ['https://zxcvbnm.ipse.ro'], // Allow requests from this origin
  methods: ['GET', 'POST'], // Allow GET and POST requests
  allowedHeaders: ['Content-Type'], // Allow Content-Type header
  credentials: true, // Allow sending cookies
  optionsSuccessStatus: 200 // Explicitly set HTTP status code for OPTIONS requests
};

// Enable CORS with custom options
app.use(cors(corsOptions));

// Log incoming requests
app.use((req, res, next) => {
  console.log(`Request from: ${req.headers.origin} to ${req.url}`);
  next();
});

// Your routes and other server logic go here

// Example route
app.post('/insert', (req, res) => {
  // Your insertion logic here
  res.status(200).send('Data inserted successfully');
});

app.listen(3000, () => {
  console.log('Server listening on port 3000');
});

When it tries sending the post request even with this script it still doesn’t work. Does anyone think they can help me?

My website is a site with a php script that is connected to a MySQL database. If there is a different way to send data to a server without cors then if you would share that with me that would be very helpful.

Please read

5 Likes

I’m sorry, but our hosting only supports hosting websites, not APIs for external things. Any such requests will be blocked by this security system before it hits your actual website:

The “CORS script” you have appears to be Node.js code to run an Express web server with CORS headers. But please note that we only provide PHP hosting, so you cannot host any Node.js code with us to begin with.

Is the website on zxcvbnm.ipse.ro a purely static site (or at least does it not use any server side code that’s not PHP)? If so, you could work around this limitation by simply moving that website to the same domain on our hosting as your database script you are already hosting with us. As long as they are on the same (sub)domain, your AJAX requests will work.

6 Likes

Hello. Thanks for the response. Can you recommend any other services?

It depends on what you need.

If you have a static website that uses Javascript in the browser to interact with PHP code that connects to a database, then you should have no problem hosting that with us.

If you insist on hosting the website separately from the backend application, then you should know that premium hosting does not have this restriction.

5 Likes

I have a static website hosted on vercel using html css and js

Hi TheUndercoverPerson,

If your site is static, remove all ties with Vercel so you keep only a set of HTML + CSS + JS files, then do what admin says about hosting a static site here under a subdomain and you’ll have no issues hosting here.

Cheers!

4 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.