Help me fix CORS error

I'm new to wappler. I've gone through all the possible tutorials available online but could not find any solution for that. All tutorials are old and for previous versions of wappler.
I'm building an android application login form.

Environment I'm using.

Wappler 7.0.0 beta 14
Framework 7 8.3.3 with app connect
Capacitor 6.2.0

CORS ERROR

Access to XMLHttpRequest at 'https://my-site.com/dmxConnect/api/security/user-login.php' from origin 'http://localhost:49849' 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.

capacitor.config.json

{ "appId": "com.example.com", "appName": "Demo App", "webDir": "www", "bundledWebRuntime": true, "plugins": { "Http": { "enabled": true } } }

Config.php (API Server)

<?php $CONFIG_DEBUG = true; $CONFIG_SECRET_KEY = 'kjhghjggjhgjg'; $CONFIG_CORS_ORIGIN = 'capacitor://,capacitor://localhost,http://localhost,capacitor-electron://localhost'; $CONFIG_CORS_METHODS = 'GET,POST,OPTIONS,CONNECT,PUT'; $CONFIG_CORS_ALLOWED_HEADERS = 'accept,authorization,content-type,origin,referer';

Hello! And welcome :slight_smile:

You need to add http://localhost:49849 (including port)

I've added but there is no change. In wappler there is no CORS error. Login is successful, but in browser or in device it's getting errors.

And you're sure config.php is uploaded to the server?

Note there's a "problem" here:

When you change from one project to another one, mobile port changes.

If you're previewing your mobile project on port 49849 and switch to the backend one and add it to config.php, then once you go back to the mobile one, the port changed again...

This is the uploaded file on server. I've opened two projects at once, so port doesn't change at all.

One more try adding:
capacitor://localhost:49849 ?

Just need to realize that everytime Wappler restarts the server for the mobile project (i.e by switching from one project to another or restarting Wappler) that the port will be different because Wappler assigns a random port to Mobile projects.

You can modify a file to set a static port and it will survive until you install a new version of Wappler.

1 Like

Cors error is fixed and I'm able to login to app. But even after successful login, there is no stored cookies showing. Kindly help

Take a look here: