mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-04 21:23:07 +00:00
fix: update server startup command to use node from PATH and improve error handling for tsx resolution
This commit is contained in:
@@ -35,12 +35,16 @@ async function startServer() {
|
|||||||
let command, args, serverPath;
|
let command, args, serverPath;
|
||||||
if (isDev) {
|
if (isDev) {
|
||||||
// In development, use tsx to run TypeScript directly
|
// In development, use tsx to run TypeScript directly
|
||||||
// Use the node executable that's running Electron
|
// Use node from PATH (process.execPath in Electron points to Electron, not Node.js)
|
||||||
command = process.execPath; // This is the path to node.exe
|
// spawn() resolves "node" from PATH on all platforms (Windows, Linux, macOS)
|
||||||
|
command = "node";
|
||||||
serverPath = path.join(__dirname, "../../server/src/index.ts");
|
serverPath = path.join(__dirname, "../../server/src/index.ts");
|
||||||
|
|
||||||
// Find tsx CLI - check server node_modules first, then root
|
// Find tsx CLI - check server node_modules first, then root
|
||||||
const serverNodeModules = path.join(__dirname, "../../server/node_modules/tsx");
|
const serverNodeModules = path.join(
|
||||||
|
__dirname,
|
||||||
|
"../../server/node_modules/tsx"
|
||||||
|
);
|
||||||
const rootNodeModules = path.join(__dirname, "../../../node_modules/tsx");
|
const rootNodeModules = path.join(__dirname, "../../../node_modules/tsx");
|
||||||
|
|
||||||
let tsxCliPath;
|
let tsxCliPath;
|
||||||
@@ -51,9 +55,13 @@ async function startServer() {
|
|||||||
} else {
|
} else {
|
||||||
// Last resort: try require.resolve
|
// Last resort: try require.resolve
|
||||||
try {
|
try {
|
||||||
tsxCliPath = require.resolve("tsx/cli.mjs", { paths: [path.join(__dirname, "../../server")] });
|
tsxCliPath = require.resolve("tsx/cli.mjs", {
|
||||||
|
paths: [path.join(__dirname, "../../server")],
|
||||||
|
});
|
||||||
} catch {
|
} catch {
|
||||||
throw new Error("Could not find tsx. Please run 'npm install' in the server directory.");
|
throw new Error(
|
||||||
|
"Could not find tsx. Please run 'npm install' in the server directory."
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,13 +113,16 @@ async function waitForServer(maxAttempts = 30) {
|
|||||||
for (let i = 0; i < maxAttempts; i++) {
|
for (let i = 0; i < maxAttempts; i++) {
|
||||||
try {
|
try {
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
const req = http.get(`http://localhost:${SERVER_PORT}/api/health`, (res) => {
|
const req = http.get(
|
||||||
|
`http://localhost:${SERVER_PORT}/api/health`,
|
||||||
|
(res) => {
|
||||||
if (res.statusCode === 200) {
|
if (res.statusCode === 200) {
|
||||||
resolve();
|
resolve();
|
||||||
} else {
|
} else {
|
||||||
reject(new Error(`Status: ${res.statusCode}`));
|
reject(new Error(`Status: ${res.statusCode}`));
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
);
|
||||||
req.on("error", reject);
|
req.on("error", reject);
|
||||||
req.setTimeout(1000, () => {
|
req.setTimeout(1000, () => {
|
||||||
req.destroy();
|
req.destroy();
|
||||||
|
|||||||
Reference in New Issue
Block a user