Skip to content

Commit

Permalink
Merge pull request #795 from lpsinger/schema-redirect
Browse files Browse the repository at this point in the history
Redirect to schema, don't bundle it
  • Loading branch information
dakota002 authored Apr 13, 2023
2 parents 4dcf45e + a8b7cca commit dfa4d89
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 38 deletions.
34 changes: 5 additions & 29 deletions app/routes/schema/$.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,12 @@
*
* SPDX-License-Identifier: NASA-1.3
*/
import '@nasa-gcn/schema'
import type { DataFunctionArgs } from '@remix-run/node'
import { readFile } from 'node:fs/promises'
import { dirname, extname, join } from 'node:path'

function isErrnoException(e: unknown): e is NodeJS.ErrnoException {
return e instanceof Error && 'code' in e && 'errno' in e
}
import { type DataFunctionArgs, redirect } from '@remix-run/node'

/* Make all JSON files at https://github.com/nasa-gcn/gcn-schema available from
* https://gcn.nasa.gov/schema */
export async function loader({ params: { '*': subPath } }: DataFunctionArgs) {
if (!subPath) throw new Error('path must be defined')

if (extname(subPath) !== '.json')
throw new Response('not found', { status: 404 })

const path = join(dirname(require.resolve('@nasa-gcn/schema')), subPath)

let body
try {
body = await readFile(path, {
encoding: 'utf-8',
})
} catch (e) {
if (isErrnoException(e) && e.code === 'ENOENT') {
throw new Response('Not found', { status: 404 })
}
throw e
}

return new Response(body, { headers: { 'Content-Type': 'application/json' } })
export async function loader({ params: { '*': path } }: DataFunctionArgs) {
return redirect(
`https://raw.githubusercontent.com/nasa-gcn/gcn-schema/main/${path ?? ''}`
)
}
8 changes: 0 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"@balavishnuvj/remix-seo": "^1.0.2",
"@nasa-gcn/architect-functions-search": "^0.2.0",
"@nasa-gcn/dynamodb-autoincrement": "^0.0.6",
"@nasa-gcn/schema": "github:nasa-gcn/gcn-schema",
"@octokit/rest": "^19.0.7",
"@opensearch-project/opensearch": "^2.2.0",
"@remix-run/architect": "^1.15.0",
Expand Down

0 comments on commit dfa4d89

Please sign in to comment.