When developing on http://localhost:8080
(non-https) and trying to retrieve data using the JavaScript SDK, the response header access-control-allow-origin
is set to HTTPS, so data cannot be retrieved. How can I work around this?
Hello @kokoro ,
Welcome to our community and thank you for trying out Backendless.
Can you provide an example of the JavaScript code you are using?
Regards, Nazar
Here’s summary of code(TypeScript):
import Backendless from "backendless"
Backendless.initApp(
process.env.NEXT_PUBLIC_BL_API_ID!,
process.env.NEXT_PUBLIC_BL_API_KEY!
)
const year = 2022
const month = 9
const day = 7
const queryBuilder = Backendless.DataQueryBuilder.create()
.addAllProperties()
.setWhereClause(`year = ${year} and month = ${month} and day = ${day}`)
.setPageSize(1)
const data = await Backendless.Data.of("diary")
console.log(data)
Hi @kokoro
I just tried to run a simple app and it works for me, no CORS issues
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JS-SDK Test CORS</title>
</head>
<script src="//api.backendless.com/sdk/js/latest/backendless.js"></script>
<body>
<script>
const APP_ID = 'xxx'
const API_KEY = 'xxx'
Backendless.initApp(APP_ID, API_KEY)
async function run() {
const result = await Backendless.Data.of('Users').find()
console.log(result)
}
run()
</script>
</body>
</html>
where is your Backendless app located, in the EU cluster?
Maybe not in EU, my subdomain is heartycup.backendless.app
.
I tried some patterns.
open as file (file:///Users/user/Downloads/backendless-cors/backendless-cors.html
): success
access-control-allow-origin: *
or access-control-allow-origin: null
open as server python3 -m http.server
(http://[::]:8000/backendless-cors.html
): success
access-control-allow-origin: http://[::]:8000
open as server python3 -m http.server
(http://localhost:8000/backendless-cors.html
): failed
access-control-allow-origin: https://localhost:8000
And I noticed that I can avoid this problem by using [::]
instead of localhost
. Thanks!
@kokoro ,
Thanks for the report. I was able to reproduce the problem. Internal ticket BKNDLSS-29654 created.
We will let you know when the problem has been fixed.
Regards,
Nazar
1 Like