Call JSON RPC with CORS

How to avoid cors error when call json rpc from browser? I want to play with rpc for this I create some html page on my local PC and try to follow JsonRpcHowTo. I know for ubus cors can be disabled with some option. But I can't find similar option for luci/rpc. So what exactly I need.

(await axios.post('https://router/cgi-bin/luci/rpc/auth', {
    id: 1,
    method: 'login',
    params: [
        'root',
        '111111',
    ]
}))

Exception

Access to XMLHttpRequest at 'https://router/cgi-bin/luci/rpc/auth' from origin 'https://localhost:4200' 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

The /luci/rpc/ endpoint is legacy and unmaintained. Don't use for new developments. It also does not support CORS.

You can use the ubus over HTTP api to perform most tasks, this api is used by LuCI itself as well.

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