Skip to content

Commit 58233b1

Browse files
committed
fix(cli): npx support
1 parent fa97470 commit 58233b1

3 files changed

Lines changed: 24 additions & 6 deletions

File tree

.changeset/public-deserts-guess.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'curl.md': patch
3+
---
4+
5+
Fixed npx support

cli/src/cli.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ const env = z.object({
2727
})
2828

2929
const vars = z.object({
30-
apiKey: z.custom<string | undefined>(),
31-
baseUrl: z.custom<string>(),
32-
client: z.custom<Client>(),
33-
commands: z.custom<Command[]>(),
34-
session: z.custom<Session.Data | null>(),
30+
apiKey: z.custom<string>().optional(),
31+
baseUrl: z.custom<string>().default(defaultBaseUrl),
32+
client: z.custom<Client>().default(undefined as never),
33+
commands: z.custom<Command[]>().default([]),
34+
session: z.custom<Session.Data | null>().default(null),
3535
})
3636

3737
const root = {

src/entry-server.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,23 @@ export default Sentry.withSentry<Env, QueueHandlerMessage>(
3131
{
3232
async fetch(request, env, ctx) {
3333
const url = new URL(request.url)
34+
3435
const firstSegment = url.pathname.split('/')[1] ?? ''
36+
const protocol =
37+
request.headers.get('x-forwarded-proto') ??
38+
(() => {
39+
const cfVisitor = request.headers.get('cf-visitor')
40+
if (!cfVisitor) return undefined
41+
try {
42+
return z.object({ scheme: z.string() }).parse(JSON.parse(cfVisitor)).scheme
43+
} catch {
44+
return undefined
45+
}
46+
})() ??
47+
url.protocol.slice(0, -1)
3548

3649
// Keep unauthenticated curl fetch paths working over HTTP, but enforce HTTPS elsewhere.
37-
if (url.protocol === 'http:' && url.hostname === env.HOST) {
50+
if (protocol === 'http' && url.hostname === env.HOST) {
3851
const isFetchPath = firstSegment.includes('.') || /^https?:$/.test(firstSegment)
3952
if (!isFetchPath) {
4053
url.protocol = 'https:'

0 commit comments

Comments
 (0)