mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(dev server): fall forward from port 1355 without portless
This commit is contained in:
+22
-7
@@ -1,6 +1,7 @@
|
||||
import { existsSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { spawn } from 'node:child_process';
|
||||
import { resolvePort } from './dev-server-utils.mjs';
|
||||
|
||||
const isWindows = process.platform === 'win32';
|
||||
const usePortless = process.env.PORTLESS !== '0' && !isWindows;
|
||||
@@ -8,15 +9,30 @@ const binDir = join(process.cwd(), 'node_modules', '.bin');
|
||||
const executableSuffix = isWindows ? '.cmd' : '';
|
||||
const portlessBin = join(binDir, `portless${executableSuffix}`);
|
||||
const viteBin = join(binDir, `vite${executableSuffix}`);
|
||||
const fallbackHost = '127.0.0.1';
|
||||
const fallbackUrlHost = '5chan.localhost';
|
||||
const fallbackRequestedPort = 1355;
|
||||
|
||||
const command = usePortless && existsSync(portlessBin) ? portlessBin : viteBin;
|
||||
const args =
|
||||
command === portlessBin
|
||||
? ['5chan', 'vite']
|
||||
: ['--host', '5chan.localhost', '--port', '1355', '--strictPort'];
|
||||
let args;
|
||||
|
||||
if (command !== portlessBin && process.env.PORTLESS !== '0') {
|
||||
console.warn('portless unavailable on this platform, using vite directly on http://5chan.localhost:1355');
|
||||
if (command === portlessBin) {
|
||||
args = ['5chan', 'vite'];
|
||||
} else {
|
||||
const port = await resolvePort(fallbackRequestedPort);
|
||||
const fallbackUrl = `http://${fallbackUrlHost}:${port}`;
|
||||
|
||||
args = ['--host', fallbackHost, '--port', String(port), '--strictPort'];
|
||||
|
||||
if (command !== portlessBin && process.env.PORTLESS !== '0') {
|
||||
console.warn(`portless unavailable on this platform, using vite directly on ${fallbackUrl}`);
|
||||
} else {
|
||||
console.log(`Starting Vite directly at ${fallbackUrl}`);
|
||||
}
|
||||
|
||||
if (port !== fallbackRequestedPort) {
|
||||
console.log(`Preferred port ${fallbackRequestedPort} is busy, so this run will use ${fallbackUrl}.`);
|
||||
}
|
||||
}
|
||||
|
||||
const child = spawn(command, args, {
|
||||
@@ -32,4 +48,3 @@ child.on('exit', (code, signal) => {
|
||||
|
||||
process.exit(code ?? 0);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user