mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-22 12:26:32 +00:00
7d93b484bd
## Description: When updating tunnel creation, the port was switched to 3000, so it pointed to master, it should be pointed to port 80 (nginx) so that nginx can route requests to the appropriate worker. Also fixed some ws handling. ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [x] I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors ## Please put your Discord username so you can be contacted if a bug or regression is found: DISCORD_USERNAME
68 lines
1.8 KiB
TypeScript
68 lines
1.8 KiB
TypeScript
import cluster from "cluster";
|
|
import * as dotenv from "dotenv";
|
|
import { GameEnv } from "../core/configuration/Config";
|
|
import { getServerConfigFromServer } from "../core/configuration/ConfigLoader";
|
|
import { Cloudflare, TunnelConfig } from "./Cloudflare";
|
|
import { startMaster } from "./Master";
|
|
import { startWorker } from "./Worker";
|
|
|
|
const config = getServerConfigFromServer();
|
|
|
|
dotenv.config();
|
|
|
|
// Main entry point of the application
|
|
async function main() {
|
|
// Check if this is the primary (master) process
|
|
if (cluster.isPrimary) {
|
|
if (config.env() !== GameEnv.Dev) {
|
|
await setupTunnels();
|
|
}
|
|
console.log("Starting master process...");
|
|
await startMaster();
|
|
} else {
|
|
// This is a worker process
|
|
console.log("Starting worker process...");
|
|
await startWorker();
|
|
}
|
|
}
|
|
|
|
// Start the application
|
|
main().catch((error) => {
|
|
console.error("Failed to start server:", error);
|
|
process.exit(1);
|
|
});
|
|
|
|
async function setupTunnels() {
|
|
const cloudflare = new Cloudflare(
|
|
config.cloudflareAccountId(),
|
|
config.cloudflareApiToken(),
|
|
config.cloudflareConfigPath(),
|
|
config.cloudflareCredsPath(),
|
|
);
|
|
|
|
const domainToService = new Map<string, string>().set(
|
|
config.subdomain(),
|
|
// TODO: change to 3000 when we have a proper tunnel setup.
|
|
`http://localhost:80`,
|
|
);
|
|
|
|
for (let i = 0; i < config.numWorkers(); i++) {
|
|
domainToService.set(
|
|
`w${i}-${config.subdomain()}`,
|
|
`http://localhost:${3000 + i + 1}`,
|
|
);
|
|
}
|
|
|
|
if (!(await cloudflare.configAlreadyExists())) {
|
|
await cloudflare.createTunnel({
|
|
subdomain: config.subdomain(),
|
|
domain: config.domain(),
|
|
subdomainToService: domainToService,
|
|
} as TunnelConfig);
|
|
} else {
|
|
console.log("Config already exists, skipping tunnel creation");
|
|
}
|
|
|
|
await cloudflare.startCloudflared();
|
|
}
|