PrismarineJS / prismarine-web-client

Minecraft web client running in your browser
https://prismarinejs.github.io/prismarine-web-client/
MIT License
447 stars 147 forks source link

Guide on how to create a proxy that can be used with the github instance #105

Open rom1504 opened 3 years ago

rom1504 commented 3 years ago

proxy code:

#!/usr/bin/env node

const express = require('express')
const netApi = require('net-browserify')

const app = express()

app.use(netApi({ allowOrigin: '*' }))

// Start the server
const server = app.listen(process.argv[2] === undefined ? 8080 : process.argv[2], function () {
  console.log('Server listening on port ' + server.address().port)
})

example of apache2 config (http):

<VirtualHost *:80>
  ProxyPreserveHost On
  ProxyRequests Off
  ServerName pproxy.rom1504.fr
  ProxyPass / http://localhost:8080/ retry=0
  ProxyPassReverse / http://localhost:8080/
RewriteEngine on
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

https:

<IfModule mod_ssl.c>
<VirtualHost *:443>
  ProxyPreserveHost On
  ProxyRequests Off
  ServerName pproxy.rom1504.fr
  ProxyPass / http://localhost:8080/ retry=0
  ProxyPassReverse / http://localhost:8080/
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/rom1504.fr-0001/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/rom1504.fr-0001/privkey.pem
RewriteEngine on
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule ^/?(.*) "ws://localhost:8080/$1" [P,L]
</VirtualHost>
</IfModule>

would be useful to have:

u9g commented 3 years ago

should this go in it's own repo? , that way we can have one click solutions in gcp/aws

rom1504 commented 3 years ago

I think it's fine in a folder of this repo

rom1504 commented 3 years ago

would be good to add a check in that proxy so it can only connect to mc server (by using mc.ping before opening the connection)

Moondarker commented 3 years ago

Nginx:

upstream mineproxy {
    server localhost:8080;
}

server {
    # listen 80; # uncomment for http
    listen 443 ssl; # comment for http

    server_name pproxy.rom1504.fr;

    ssl_certificate /etc/letsencrypt/live/rom1504.fr-0001/fullchain.pem; # comment for http
    ssl_certificate_key /etc/letsencrypt/live/rom1504.fr-0001/privkey.pem; # comment for http

    location / {
        proxy_pass http://mineproxy;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection upgrade;
        proxy_set_header Host $host;
    }
}