Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit adbfd45

Browse files
committed
Don't spawn WS server, if laravel-websockets is not installed
1 parent dbfe4a0 commit adbfd45

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

dist/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const killChildProcesses = () => {
2525
let processes = [
2626
...phpProcesses,
2727
websocketProcess,
28-
];
28+
].filter((p) => p !== undefined);
2929
processes.forEach((process) => {
3030
try {
3131
ps_node_1.default.kill(process.pid);

dist/server/websockets.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
33
return (mod && mod.__esModule) ? mod : { "default": mod };
44
};
55
Object.defineProperty(exports, "__esModule", { value: true });
6+
const fs_1 = require("fs");
7+
const path_1 = require("path");
68
const child_process_1 = require("child_process");
79
const php_1 = require("./php");
810
const state_1 = __importDefault(require("./state"));
911
function serveWebsockets() {
10-
const phpServer = (0, child_process_1.spawn)(state_1.default.php, ['artisan', 'websockets:serve'], {
11-
cwd: (0, php_1.getAppPath)(),
12+
if (!(0, fs_1.existsSync)((0, path_1.join)((0, php_1.getAppPath)(), 'vendor', 'beyondcode', 'laravel-websockets'))) {
13+
return;
14+
}
15+
const phpServer = (0, child_process_1.spawn)(state_1.default.php, ["artisan", "websockets:serve"], {
16+
cwd: (0, php_1.getAppPath)()
1217
});
13-
phpServer.stdout.on('data', (data) => {
18+
phpServer.stdout.on("data", (data) => {
1419
});
15-
phpServer.stderr.on('data', (data) => {
20+
phpServer.stderr.on("data", (data) => {
1621
});
1722
return phpServer;
1823
}

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const killChildProcesses = () => {
1717
let processes = [
1818
...phpProcesses,
1919
websocketProcess,
20-
];
20+
].filter((p) => p !== undefined);
2121

2222
processes.forEach((process) => {
2323
try {

src/server/websockets.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1-
import { spawn } from 'child_process'
2-
import { getAppPath } from './php'
3-
import state from './state'
1+
import { existsSync } from "fs";
2+
import { join } from "path";
3+
import { spawn } from "child_process";
4+
import { getAppPath } from "./php";
5+
import state from "./state";
46

57
function serveWebsockets() {
6-
const phpServer = spawn(state.php, ['artisan', 'websockets:serve'], {
7-
cwd: getAppPath(),
8-
})
8+
if (!existsSync(join(getAppPath(), 'vendor', 'beyondcode', 'laravel-websockets'))) {
9+
return;
10+
}
911

10-
phpServer.stdout.on('data', (data) => {
11-
})
12+
const phpServer = spawn(state.php, ["artisan", "websockets:serve"], {
13+
cwd: getAppPath()
14+
});
1215

13-
phpServer.stderr.on('data', (data) => {
14-
})
16+
phpServer.stdout.on("data", (data) => {
17+
});
18+
19+
phpServer.stderr.on("data", (data) => {
20+
});
1521
return phpServer;
1622
}
1723

0 commit comments

Comments
 (0)