Hooks
A hook to automatically add CORS headers
An Exobase hook that automatically responds to OPTIONS
requests with standard CORS headers. Also allows you to extends and override the headers with your own values as needed.
yarn add @exobase/use-cors
# or
yarn add @exobase/hooks
import { useCors } from '@exobase/use-cors'
// or
import { useCors } from '@exobase/hooks'
Add the useCors
hook anywhere before your endpoint. When an OPTIONS
request is handled the useCors
hook will resopnd with the configured (or default) CORS headers and will not call your endpoint function.
import { compose } from 'radash'
import type { Props } from '@exobase/core'
import { useExpress } from '@exobaes/use-express'
import { useCors } from '@exobase/use-cors'
// Not called when request.method = 'OPTIONS'
const endpoint = (props: Props) => {
return {
message: 'success'
}
}
export default compose(useExpress(), useCors(), endpoint)