How to solve cross domain in local development?

My local domain name is localhost:3000, and I want to fetch data from other domain names locally. what do I do?

Hi @wenqi,

in theory this is unrelated to Theia, but in practice you can actually circumvent CORS issues by injecting ProxyingBrowserRequestService in the frontend. That service is available since v1.26.0. You’ll have to bind it manually like bind(ProxyingBrowserRequestService).toSelf().inSingletonScope(), but any request through that service will be proxied through the backend of your Theia app.

thank you! But I still don’t know the specific operation, can you give me an example?

    const response = await this.proxyingBrowserRequestService.request({url, headers: {'Access-Control-Allow-Origin': '*'}})

I get this result

buffer: Uint8Array(821) [60, 33, 68, 79, 67, 84, 89, 80, 69, 32, 104, 116, 109, 108, 62, 60, 104, 116, 109, 108, 32, 108, 97, 110, 103, 61, 34, 122, 104, 34, 62, 60, 104, 101, 97, 100, 62, 60, 109, 101, 116, 97, 32, 99, 104, 97, 114, 115, 101, 116, 61, 34, 117, 116, 102, 45, 56, 34, 62, 60, 109, 101, 116, 97, 32, 104, 116, 116, 112, 45, 101, 113, 117, 105, 118, 61, 34, 88, 45, 85, 65, 45, 67, 111, 109, 112, 97, 116, 105, 98, 108, 101, 34, 32, 99, 111, 110, 116, 101, 110, …]
res:
headers:
accept-ranges: "bytes"
connection: "close"
content-length: "821"
content-type: "text/html"
date: "Thu, 14 Jul 2022 06:08:55 GMT"
etag: "\"62ce712a-335\""
last-modified: "Wed, 13 Jul 2022 07:15:54 GMT"
[[Prototype]]: Object
statusCode: 200
[[Prototype]]: Object
url: "https://dev.srdcloud.cn/login/oauth/authorize?response_type=code&client_id=20b154111080gbc75qo2&state=abcdefg"

did not make a request,I do not know what to do?

@wenqi it looks like the request made it through successfully, doesn’t it? A status code of 200 indicates a successful request.

Anyway, to actually work with the data inside of the buffer, you’ll have to call RequestContext.asText or RequestContext.asJson.

thank you very much

can i use webpack-dev-server
devServer: {
port: 8001,
headers: {
“Access-Control-Allow-Origin”: ""
},
proxy: {
'
’: {
target: ‘https://dev.srdcloud.cn’,
}
},
},
solve cross domain?