colyseus / proxy

🔀⚔ Proxy and Service Discovery for Colyseus 0.10 ~ 0.14 (Not recommended on 0.15+)
https://docs.colyseus.io/scalability/
MIT License
37 stars 25 forks source link

have cross-domain issues #1

Closed Yinmany closed 4 years ago

endel commented 5 years ago

it seems the proxy module we're using doesn't support CORS currently 😨 https://github.com/OptimalBits/redbird/pull/111

the implementation of @colyseus/proxy is super simple, maybe we need an alternative to redbird? I'm using redbird because it allows to easily determine a specific server based on the URL received. (dynamic proxy)

some alternatives may be:

Yinmany commented 5 years ago

Thank you. I have solved the problem of CORS. But proxy has a new problem: I ran mongodb and redis with no data, ran the proxy, ran two instances of colyseus, and then the room called joinOrCreate and had a problem, following proxy logs:

{"name":"redbird","hostname":"DESKTOP-AD0QGAB","pid":10520,"level":40,"src":"127.0.0.1","url":"/matchmake/joinOrCreate/my_room","msg":"no valid route found for given source","time":"2019-09-01T08:58:14.316Z","v":0}

And then I printed it matchedProcessId and processIds,but matchedProcessId is null:

const proxy = require('redbird')({
  port: Number(process.env.PORT || 80),
  resolvers: [function (host: string, url: string) {
    const matchedProcessId = url.match(/\/([a-zA-Z0-9\-_]+)\/[a-zA-Z0-9\-_]+\?/);
    console.log(`host:${host} url:${url} matchedProcessId:${matchedProcessId} processIds:`, processIds);

    if (matchedProcessId && matchedProcessId[1]) {
      return processIds[matchedProcessId[1]];
    }
  }]
});
host:127.0.0.1 url:/matchmake/joinOrCreate/my_room matchedProcessId:null processIds: { '5nFI5vu90': 'http://[::]:3001',
  '0tEX-Y_rt': 'http://[::]:3000' }

mongodb not datas

redis datas colyseus:nodes:

row value
1 5nFI5vu90/[::]:3001
2 0tEX-Y_rt/[::]:3000

Does matchedProcessId have no processId, does random processId work?

endel commented 5 years ago

Hi @Yinmany, that's correct, when the matchedProcessId is not present in the URL, a random (round robin) process is selected for the request.

I've just tried running the colyseus-examples project through the proxy and it's working fine. Can you provide a sample project where I can reproduce the issue you're having?

In the test I've made, I have 4 colyseus processes running (port 3000, 3001, 3002, 3003), and the proxy running locally on port 2567. The proxy is the only public endpoint to be used in the application. When I go to http://localhost:2567 I can navigate to the example pages and connect to the rooms successfully.

Cheers

Yinmany commented 5 years ago

Hi @endel I've changed it to this, and it's working fine:

  resolvers: [function (host: string, url: string) {
    const matchedProcessId = url.match(/\/([a-zA-Z0-9\-_]+)\/[a-zA-Z0-9\-_]+\?/);

    if (matchedProcessId && matchedProcessId[1]) {
      return processIds[matchedProcessId[1]];
    }

    if (pids.length > 0) {
      let idx = Math.floor(Math.random() * pids.length);
      return processIds[pids[idx]];
    }
  }]

It used to be, when everything is new, a process doesn't work well without being random.But now everything is fine.

Cheers!

endel commented 4 years ago

I'm closing this as it seems not to be a problem anymore, feel free to re-open if you need to @Yinmany