Coder Social home page Coder Social logo

gddark / proxy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from colyseus/proxy

0.0 0.0 0.0 52 KB

๐Ÿ”€โš” Proxy and Service Discovery for Colyseus (0.10.x)

Home Page: https://colyseus.io

License: MIT License

JavaScript 1.84% TypeScript 98.16%

proxy's Introduction

@colyseus/proxy

Proxy and Service Discovery for Colyseus

Architecture representation

Running the Proxy

Clone, this project and install its dependencies:

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

Edit the .env file to meet your needs:

  • HOST is your public domain name.
  • 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.

Start the proxy server:

npx ts-node proxy.ts

Configuring Colyseus + PM2

  • Configure RedisPresence
  • Bind each instance of the server on a different port
  • Use PM2 to manage Colyseus instances
import { Server, RedisPresence } from "colyseus";

// 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"
    })
})

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.

npm install -g pm2

Use the following ecosystem.config.js configuration:

// ecosystem.config.js
const os = require('os');
module.exports = {
    apps: [{
        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    โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ colyseus โ”‚ 0  โ”‚ fork โ”‚ online โ”‚ 0 โ”‚ 0%  โ”‚ 15.4 MB   โ”‚
โ”‚ colyseus โ”‚ 1  โ”‚ 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

proxy's People

Contributors

endel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.