Skip to content

Commit

Permalink
simplify allowOrigin
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Jan 17, 2025
1 parent 51f0b7f commit b2347e5
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,24 +103,15 @@ const tracePreflight = (request: Request) =>

function allowOrigin(request: Request): string {
const origin = request.headers.get('Origin')
if (origin && ALLOWED_ORIGINS.has(origin)) {
// if the origin is one of the allowed origins, return that to allow requests for that origin
if (origin && origin.startsWith('http://localhost:')) {
// allow all localhost ports
return origin
} else {
// otherwise we return the default origin to prevent requests from other origins
return DEFAULT_ALLOW_ORIGIN
// otherwise do the simple thing and allow just https://logfire.run
return 'https://logfire.run'
}
}

const DEFAULT_ALLOW_ORIGIN = 'https://logfire.run'
const ALLOWED_ORIGINS = new Set([
'http://localhost:8000',
'http://localhost:8787',
'http://localhost:8788',
'https://logfire.run',
'https://pydantic.run',
])

async function getBody(request: Request): Promise<ArrayBuffer> {
if (request.body === null) {
throw new Error('Request body is null')
Expand Down

0 comments on commit b2347e5

Please sign in to comment.