-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #357 from StampyAI/redirects
Coda configurable redirects
- Loading branch information
Showing
5 changed files
with
57 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type {LoaderArgs} from '@remix-run/cloudflare' | ||
import {redirect} from '@remix-run/cloudflare' | ||
import {loadRedirects} from '~/server-utils/stampy' | ||
|
||
export const loader = async ({request, params}: LoaderArgs) => { | ||
try { | ||
const {data: redirects} = await loadRedirects(request) | ||
const to = params['*'] && redirects[params['*'].replace(/^\/+/, '')] | ||
if (to) return redirect(to) | ||
} catch (e) { | ||
console.error(e) | ||
} | ||
throw new Response(null, { | ||
status: 404, | ||
statusText: 'Not Found', | ||
}) | ||
} | ||
|
||
const RenderUI = () => { | ||
// This should never be called, but is required for Remix to treat it as an UI route | ||
return null | ||
} | ||
export default RenderUI |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
/** @type {import('@remix-run/dev').AppConfig} */ | ||
const routes = (defineRoutes) => { | ||
return defineRoutes((route) => { | ||
route('/*', 'routes/$redirects.tsx') | ||
}) | ||
} | ||
|
||
module.exports = { | ||
serverConditions: ['worker'], | ||
serverMainFields: ['browser', 'module', 'main'], | ||
serverModuleFormat: 'esm', | ||
serverPlatform: 'neutral', | ||
serverDependenciesToBundle: 'all', | ||
server: './server.js', | ||
routes, | ||
} |