npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@colyseus/proxy

v0.12.11

Published

Proxy and Service Discovery for Colyseus

Downloads

818

Readme

@colyseus/proxy

Proxy and Service Discovery for Colyseus

For a quickstart see Configuring Proxy + Colyseus + PM2

Running the Proxy

The easiest way to get @colyseus/proxy running is to install it globally.

This can be done by running:

npm install -g @colyseus/proxy

Edit your runtime environment to contain the following environment variables:

  • PORT is the port the proxy will be running on.
  • REDIS_URL is the path to the same Redis instance you're using on Colyseus' processes.
  • HEALTH_CHECK_PATH is an optional health check path, for example /health. The health check path always returns an HTTP 200 response. Prefix the value with an asterisk to match a path ending, for example */health.

Once installed it can be run with

colyseus-proxy

Running the Proxy From Source

Clone, this project and install its dependencies:

git clone https://github.com/colyseus/proxy.git
cd proxy
npm install

Edit your environment to contain the following environment variables:

  • PORT is the port the proxy will be running on.
  • REDIS_URL is the path to the same Redis instance you're using on Colyseus' processes.
  • HEALTH_CHECK_PATH is an optional health check path, for example /health. The health check path always returns an HTTP 200 response. Prefix the value with an asterisk to match a path ending, for example */health.

Start the proxy server:

npx ts-node proxy.ts

Configuring Proxy + Colyseus + PM2

  • Install @colyseus/proxy (npm install --save @colyseus/proxy)
  • Configure RedisPresence
  • Configure MongooseDriver
  • Bind each instance of the server on a different port
  • Use PM2 to manage Colyseus and Proxy instances

Configure the colyseus application:

import { Server, RedisPresence } from "colyseus";
import { MongooseDriver } from "colyseus/lib/matchmaker/drivers/MongooseDriver"

// binds each instance of the server on a different port.
const PORT = Number(process.env.PORT) + Number(process.env.NODE_APP_INSTANCE);

const gameServer = new Server({
    presence: new RedisPresence({
        url: "redis://127.0.0.1:6379/0"
    }),
    driver: new MongooseDriver(),
})

gameServer.listen(PORT);
console.log("Listening on", PORT);

It's recommended to use PM2 to manage your server instances. PM2 allows to scale Node.js processes up and down within your server. PM2 can also be used to manage and scale up the proxy instances.

npm install -g pm2

Use the following ecosystem.config.js configuration:

// ecosystem.config.js
const os = require('os');
module.exports = {
    apps: [
         {
            port        : 80,
            name        : "colyseus-proxy",
            script      : "./node_modules/@colyseus/proxy/bin/proxy",
            instances   : 1, // scale this up if the proxy becomes the bottleneck
            exec_mode   : 'cluster',
            env: {
                PORT: 80,
                REDIS_URL: "redis://127.0.0.1:6379/0"
            }
        },
        {
            port        : 8080,
            name        : "colyseus",
            script      : "lib/index.js", // your entrypoint file
            watch       : true,           // optional
            instances   : os.cpus().length,
            exec_mode   : 'fork',         // IMPORTANT: do not use cluster mode.
            env: {
                DEBUG: "colyseus:errors",
                NODE_ENV: "production",
            }
        }
    ]
}

Now you're ready to start multiple Colyseus proceses.

pm2 start

If you're using TypeScript, compile your project before running pm2 start, via npx tsc.

You should see the following output, depending on the amount of processes your server have:

[PM2][WARN] Applications colyseus not running, starting...
[PM2] App [colyseus] launched (2 instances)
┌──────────┬────┬─────────┬────────┬───┬─────┬───────────┐
│ Name     │ id │ mode    │ status │ ↺ │ cpu │ memory    │
├──────────┼────┼─────────┼────────┼───┼─────┼───────────┤
│ proxy    │ 0  │ cluster │ online │ 0 │ 0%  │ 7.4 MB    │
│ colyseus │ 1  │ fork    │ online │ 0 │ 0%  │ 15.4 MB   │
│ colyseus │ 2  │ fork    │ online │ 0 │ 0%  │ 12.3 MB   │
└──────────┴────┴─────────┴────────┴───┴─────┴───────────┘
Use `pm2 show <id|name>` to get more details about an app

Now, run pm2 logs to check if you don't have any errors.

LICENSE

MIT