-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into brophdawg11/fetcher-persist
- Loading branch information
Showing
15 changed files
with
648 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"@remix-run/express": patch | ||
--- | ||
|
||
Allow the `@remix-run/express` adapter to work behind a proxy when using `app.enable('trust proxy')` | ||
|
||
- Previously, this used `req.get('host')` to construct the Remix `Request`, but that does not respect `X-Forwarded-Host` | ||
- This now uses `req.hostname` which will respect `X-Forwarded-Host` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { spawn } from "node:child_process"; | ||
import type { Readable } from "node:stream"; | ||
import execa from "execa"; | ||
import getPort from "get-port"; | ||
import resolveBin from "resolve-bin"; | ||
import waitOn from "wait-on"; | ||
|
||
const isWindows = process.platform === "win32"; | ||
|
||
export async function viteDev( | ||
projectDir: string, | ||
options: { port?: number } = {} | ||
) { | ||
let viteBin = resolveBin.sync("vite"); | ||
return node(projectDir, [viteBin, "dev"], options); | ||
} | ||
|
||
export async function node( | ||
projectDir: string, | ||
command: string[], | ||
options: { port?: number } = {} | ||
) { | ||
let nodeBin = process.argv[0]; | ||
let proc = spawn(nodeBin, command, { | ||
cwd: projectDir, | ||
env: process.env, | ||
stdio: "pipe", | ||
}); | ||
let devStdout = bufferize(proc.stdout); | ||
let devStderr = bufferize(proc.stderr); | ||
|
||
let port = options.port ?? (await getPort()); | ||
await waitOn({ | ||
resources: [`http://localhost:${port}/`], | ||
timeout: 10000, | ||
}).catch((err) => { | ||
let stdout = devStdout(); | ||
let stderr = devStderr(); | ||
throw new Error( | ||
[ | ||
err.message, | ||
"", | ||
"exit code: " + proc.exitCode, | ||
"stdout: " + stdout ? `\n${stdout}\n` : "<empty>", | ||
"stderr: " + stderr ? `\n${stderr}\n` : "<empty>", | ||
].join("\n") | ||
); | ||
}); | ||
|
||
return { pid: proc.pid!, port: port }; | ||
} | ||
|
||
export async function kill(pid: number) { | ||
if (!isAlive(pid)) return; | ||
if (isWindows) { | ||
await execa("taskkill", ["/F", "/PID", pid.toString()]).catch((error) => { | ||
// taskkill 128 -> the process is already dead | ||
if (error.exitCode === 128) return; | ||
if (/There is no running instance of the task./.test(error.message)) | ||
return; | ||
console.warn(error.message); | ||
}); | ||
return; | ||
} | ||
await execa("kill", ["-9", pid.toString()]).catch((error) => { | ||
// process is already dead | ||
if (/No such process/.test(error.message)) return; | ||
console.warn(error.message); | ||
}); | ||
} | ||
|
||
// utils ------------------------------------------------------------ | ||
|
||
function bufferize(stream: Readable): () => string { | ||
let buffer = ""; | ||
stream.on("data", (data) => (buffer += data.toString())); | ||
return () => buffer; | ||
} | ||
|
||
function isAlive(pid: number) { | ||
try { | ||
process.kill(pid, 0); | ||
return true; | ||
} catch (error) { | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.