Files
OpenFrontIO/src/server/Server.ts
T
Scott Anderson 1da46cfef2 Enable the @stylistic/ts/quotes eslint rule (#1850)
## Description:

Enable the `@stylistic/ts/quotes` eslint rule.

Fixes #1788

## 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
2025-08-17 21:00:16 -04:00

68 lines
1.8 KiB
TypeScript

import * as dotenv from "dotenv";
import { Cloudflare, TunnelConfig } from "./Cloudflare";
import { GameEnv } from "../core/configuration/Config";
import cluster from "cluster";
import { getServerConfigFromServer } from "../core/configuration/ConfigLoader";
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({
domain: config.domain(),
subdomain: config.subdomain(),
subdomainToService: domainToService,
} as TunnelConfig);
} else {
console.log("Config already exists, skipping tunnel creation");
}
await cloudflare.startCloudflared();
}