access server via proxied subpath

main v1.3
Benjamin Kraft 1 year ago
parent fe56f13898
commit afa99582af
  1. 49
      public/data/scripts/online.js
  2. 3
      public/data/settings/get_port.php
  3. 4
      server/src/index.ts
  4. 18
      server/src/start.ts

@ -2,36 +2,35 @@
function socketConnect(project, name = "noone"){ function socketConnect(project, name = "noone"){
let urlQueries = '?game=' + project.name + '&name=' + name; let urlQueries = '?game=' + project.name + '&name=' + name;
$.get('data/settings/get_port.php', port => { let url = 'https://' + location.hostname + urlQueries;
let url = 'https://' + location.hostname + ':' + port + urlQueries; socket = io.connect(url, {
path: "/global-draw/"
});
socket.on('connect', () => {
console.log('Connected to ', url);
socket = io.connect(url); socket.emit('join-lobby', 'global-draw-room');
socket.on('connect', () => {
console.log('Connected to ', url);
socket.emit('join-lobby', 'global-draw-room'); socket.on('add-line', (lobby, line) => drawer.addLine(line));
socket.on('fill-pixel', (lobby, pixel) => drawer.fillPixel(pixel));
socket.on('add-all', (lines) => drawer.onLinesLoaded(lines));
socket.on('fill-all', (pixels) => drawer.onPixelsLoaded(pixels));
socket.on('member-joined', (lobby, clientId) => {
if (clientId !== socket.id)
return;
if (drawer)
if (drawer.lines.length !== 0)
return;
socket.on('add-line', (lobby, line) => drawer.addLine(line)); socket.emit('request-all-lines');
socket.on('fill-pixel', (lobby, pixel) => drawer.fillPixel(pixel)); socket.emit('request-all-pixels');
socket.on('add-all', (lines) => drawer.onLinesLoaded(lines)); $("#action").html("Downloading...");
socket.on('fill-all', (pixels) => drawer.onPixelsLoaded(pixels)); });
socket.on('member-joined', (lobby, clientId) => {
if (clientId !== socket.id)
return;
if (drawer)
if (drawer.lines.length !== 0)
return;
socket.emit('request-all-lines'); socket.on('all-saved', (_lobby) => drawer.answerServerSave());
socket.emit('request-all-pixels');
$("#action").html("Downloading...");
});
socket.on('all-saved', (_lobby) => drawer.answerServerSave()); updateDrawType($("input[type=radio][name=type]:checked").val());
});
updateDrawType($("input[type=radio][name=type]:checked").val());
});
});
} }
function sendFeedback(){ function sendFeedback(){

@ -1,3 +0,0 @@
<?php
echo parse_ini_file("../../../server/.env")["HTTPS_PORT"];

@ -3,5 +3,7 @@ import {StartServer} from "./start";
StartServer({ StartServer({
useP2P: false, useP2P: false,
gameClass: GlobalDraw gameClass: GlobalDraw,
subPath: "/global-draw/",
port: 3101
}); });

@ -3,30 +3,26 @@ import {log} from "./logger.js";
import {Server} from 'socket.io'; import {Server} from 'socket.io';
import {Room} from "./room.js"; import {Room} from "./room.js";
import * as https from "https"; import * as http from "http";
import * as fs from "fs";
export function StartServer(settings: any){ export function StartServer(settings: any){
require("dotenv").config(); require("dotenv").config();
const httpsPort = parseInt(process.env.HTTPS_PORT);
let cert = fs.readFileSync(`${process.env.SSL_PATH}/cert.pem`); let httpServer = http.createServer();
let key = fs.readFileSync(`${process.env.SSL_PATH}/key.pem`);
let httpsServer = https.createServer({key: key, cert: cert}); let sIO = new Server(httpServer, {
let sIO = new Server(httpsServer, {
cors: { cors: {
origin: ["https://play.benjamin-kraft.local", "https://play.benjamin-kraft.eu"] origin: ["https://play.benjamin-kraft.local", "https://play.benjamin-kraft.eu"]
} },
path: settings.subPath
}); });
if (settings.useP2P){ if (settings.useP2P){
const p2p = require('socket.io-p2p-server').Server; const p2p = require('socket.io-p2p-server').Server;
sIO.use(p2p); sIO.use(p2p);
} }
httpsServer.listen(httpsPort); httpServer.listen(settings.port);
Room.GameClass = settings.gameClass; Room.GameClass = settings.gameClass;
@ -35,5 +31,5 @@ export function StartServer(settings: any){
// On new connection // On new connection
sIO.on('connection', socket => connectionManager.newSocket(socket)); sIO.on('connection', socket => connectionManager.newSocket(socket));
log('startup', null, null, 'Server is listening on port ' + httpsPort); log('startup', null, null, 'Server is listening on port ' + settings.port);
} }
Loading…
Cancel
Save