-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
61 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
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { Handler, Env } from 'hono'; | ||
|
||
export const api = <E extends Env = any>(): Handler<E> => { | ||
return async (ctx) => { | ||
return ctx.json({ ok: false }); | ||
}; | ||
}; |
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,26 @@ | ||
import { Hono } from 'hono'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore This file won’t exist if it hasn’t yet been built | ||
import * as build from '../build/server'; // eslint-disable-line import/no-unresolved | ||
|
||
import type { Bindings } from './types'; | ||
|
||
import { api } from './api'; | ||
import { remix } from './remix'; | ||
|
||
export const app = new Hono<{ Bindings: Bindings }>(); | ||
|
||
app.all('*', remix({ build })); | ||
|
||
app.all('/api/*', api()); | ||
|
||
app.onError((err, c) => { | ||
if (err.message) { | ||
console.log(...err.message.trim().split('\n')); | ||
} | ||
if (err.stack) { | ||
console.log(...err.stack.trim().split('\n')); | ||
} | ||
return c.json({ status: 500, messsage: err?.message ?? 'Internal Error' }, 500); | ||
}); |
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,22 @@ | ||
import type { Handler, Env } from 'hono'; | ||
|
||
import { createRequestHandler, type ServerBuild } from '@remix-run/node'; | ||
|
||
export interface RemixHandlerOptions { | ||
build: ServerBuild; | ||
} | ||
|
||
export const remix = <E extends Env = any>(options: RemixHandlerOptions): Handler<E> => { | ||
const handleRemixRequest = createRequestHandler(options.build); | ||
|
||
return async (ctx) => { | ||
const request = ctx.req.raw; | ||
|
||
try { | ||
const loadContext = {}; | ||
return await handleRemixRequest(request, loadContext); | ||
} catch (error) { | ||
throw error; | ||
} | ||
}; | ||
}; |
File renamed without changes.