Skip to content

Getting Origin header #59

Answered by kwhitley
EduM22 asked this question in Q&A
Discussion options

You must be logged in to vote

Sorry I'm just now seeing this! Wish GH would add badges next to Discussions for unanswered ones...

Perhaps try something like this?

// index.js
import { Router } from 'itty-router'
import { error } from 'itty-router-extras'

const router = Router()

// add routes (not shown)

export default {
  fetch: (request, ...args) => router
                        .handle(request, ...args)
                        .catch((err) => {
                          const referer = request.headers.get('Referer')
                          // do something with it
                          
                          return error(500, 'Not really a 500, but you get the point')
                        })
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by EduM22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants