generated from SatooRu65536/tpl-remix-vite
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
8ed5d27
commit 1eb216c
Showing
8 changed files
with
118 additions
and
59 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,15 @@ | ||
{ | ||
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json", | ||
"version": "0.2", | ||
"ignorePaths": [ | ||
"node_modules", | ||
"/package.json" | ||
], | ||
"words": [ | ||
"cloudflare", | ||
"datasource", | ||
"prisma", | ||
"sqlite", | ||
"uuid" | ||
] | ||
} |
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,9 @@ | ||
import { PrismaD1 } from '@prisma/adapter-d1'; | ||
import { PrismaClient } from '@prisma/client'; | ||
|
||
// ref: https://github.com/chimame/remix-prisma-d1-on-cloudflare-pages/blob/e98cfb57b80e836186ef587a69941b61fe5cd09d/app/database/client.ts | ||
|
||
export async function injectPrismaClient(db: D1Database): Promise<PrismaClient> { | ||
const adapter = new PrismaD1(db); | ||
return new PrismaClient({ adapter }); | ||
} |
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,6 +1,11 @@ | ||
/* eslint-disable no-restricted-imports */ | ||
|
||
import type { createPagesFunctionHandlerParams } from '@remix-run/cloudflare-pages'; | ||
import { createPagesFunctionHandler } from '@remix-run/cloudflare-pages'; | ||
// eslint-disable-next-line no-restricted-imports | ||
// @ts-expect-error ビルドされたら解決されるので無視 | ||
import * as build from '../build/server'; | ||
import { getLoadContext } from '../load-context'; | ||
|
||
export const onRequest = createPagesFunctionHandler({ build } as createPagesFunctionHandlerParams<any>); | ||
export const onRequest = createPagesFunctionHandler( | ||
{ build, getLoadContext } as unknown as createPagesFunctionHandlerParams<any>, | ||
); |
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,27 @@ | ||
import type { AppLoadContext } from '@remix-run/cloudflare'; | ||
import type { PlatformProxy } from 'wrangler'; | ||
import { Database } from '@/services/db.server'; | ||
import { injectPrismaClient } from './app/services/__prisma.server'; | ||
|
||
type Cloudflare = Omit<PlatformProxy<Env>, 'dispose'>; | ||
|
||
declare module '@remix-run/cloudflare' { | ||
interface AppLoadContext { | ||
cloudflare: Cloudflare; | ||
__prisma: Awaited<ReturnType<typeof injectPrismaClient>>; | ||
db: Database; | ||
} | ||
} | ||
|
||
// ref: https://github.com/chimame/remix-prisma-d1-on-cloudflare-pages/blob/e98cfb57b80e836186ef587a69941b61fe5cd09d/load-context.ts | ||
export async function getLoadContext({ context }: { | ||
request: Request; | ||
context: { cloudflare: Cloudflare }; | ||
}): Promise<AppLoadContext> { | ||
const prisma = await injectPrismaClient(context.cloudflare.env.DB); | ||
return { | ||
...context, | ||
__prisma: prisma, | ||
db: new Database(prisma), | ||
}; | ||
} |
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