Skip to content

Commit

Permalink
Merge pull request #2762 from lpsinger/405
Browse files Browse the repository at this point in the history
Return correct HTTP status for disallowed HTTP methods
  • Loading branch information
dakota002 authored Dec 9, 2024
2 parents 3326e65 + 7ef038e commit e0775ca
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 26 deletions.
2 changes: 1 addition & 1 deletion app/components/CircularsEmailAddress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useHostname } from '~/root'

export function useCircularsEmailAddress() {
let hostname = useHostname()
if (!hostname.endsWith('gcn.nasa.gov')) hostname = 'test.gcn.nasa.gov'
if (!hostname?.endsWith('gcn.nasa.gov')) hostname = 'test.gcn.nasa.gov'
return `circulars@${hostname}`
}

Expand Down
2 changes: 1 addition & 1 deletion app/components/NoticeFormat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function NoticeFormatInput({
onChange,
}: {
name: string
showJson: boolean
showJson?: boolean
value?: NoticeFormat
onChange?: (arg: NoticeFormat) => void
}) {
Expand Down
2 changes: 1 addition & 1 deletion app/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function getFormDataString(formData: FormData, key: string) {
}
}

export function getEnvBannerHeaderAndDescription(hostname: string) {
export function getEnvBannerHeaderAndDescription(hostname?: string) {
const production_hostname = 'gcn.nasa.gov'
let heading, description
if (hostname === `dev.${production_hostname}`) {
Expand Down
38 changes: 16 additions & 22 deletions app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,39 +138,31 @@ export function shouldRevalidate() {
}

function useLoaderDataRoot() {
const result = useRouteLoaderData<typeof loader>('root')
invariant(result)
return result
return useRouteLoaderData<typeof loader>('root')
}

export function useUserIdp() {
const { idp } = useLoaderDataRoot()
return idp
return useLoaderDataRoot()?.idp
}

export function useEmail() {
const { email } = useLoaderDataRoot()
return email
return useLoaderDataRoot()?.email
}

export function useName() {
const { name } = useLoaderDataRoot()
return name
return useLoaderDataRoot()?.name
}

export function useModStatus() {
const { userIsMod } = useLoaderDataRoot()
return userIsMod
return useLoaderDataRoot()?.userIsMod
}

export function useSubmitterStatus() {
const { userIsVerifiedSubmitter } = useLoaderDataRoot()
return userIsVerifiedSubmitter
return useLoaderDataRoot()?.userIsVerifiedSubmitter
}

export function useRecaptchaSiteKey() {
const { recaptchaSiteKey } = useLoaderDataRoot()
return recaptchaSiteKey
return useLoaderDataRoot()?.recaptchaSiteKey
}

/**
Expand All @@ -183,7 +175,7 @@ export function useRecaptchaSiteKey() {
*/
export function useFeature(feature: string) {
const featureUppercase = feature.toUpperCase()
return useLoaderDataRoot().features.includes(featureUppercase)
return useLoaderDataRoot()?.features.includes(featureUppercase)
}

export function WithFeature({
Expand All @@ -195,8 +187,13 @@ export function WithFeature({
return <>{useFeature(Object.keys(features)[0]) && children}</>
}

export function useOrigin() {
return useLoaderDataRoot()?.origin
}

export function useUrl() {
const { origin } = useLoaderDataRoot()
const origin = useOrigin()
invariant(origin)
const { pathname, search, hash } = useLocation()
const url = new URL(origin)
url.pathname = pathname
Expand All @@ -205,12 +202,9 @@ export function useUrl() {
return url.toString()
}

export function useOrigin() {
return useLoaderDataRoot().origin
}

export function useHostname() {
return new URL(useLoaderDataRoot().origin).hostname
const origin = useOrigin()
if (origin) return new URL(origin).hostname
}

export function useDomain() {
Expand Down
6 changes: 5 additions & 1 deletion app/routes/$.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { SEOHandle } from '@nasa-gcn/remix-seo'
import type { LoaderFunction } from '@remix-run/node'
import type { ActionFunction, LoaderFunction } from '@remix-run/node'

import type { BreadcrumbHandle } from '~/root/Title'

Expand All @@ -12,4 +12,8 @@ export const loader: LoaderFunction = function () {
throw new Response(null, { status: 404 })
}

export const action: ActionFunction = function () {
throw new Response(null, { status: 404 })
}

export default function () {}

0 comments on commit e0775ca

Please sign in to comment.