Initial commit from create-react-router
This commit is contained in:
33
server/app.ts
Normal file
33
server/app.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { createRequestHandler } from "@react-router/express";
|
||||
import { drizzle } from "drizzle-orm/postgres-js";
|
||||
import express from "express";
|
||||
import postgres from "postgres";
|
||||
import "react-router";
|
||||
|
||||
import { DatabaseContext } from "~/database/context";
|
||||
import * as schema from "~/database/schema";
|
||||
|
||||
declare module "react-router" {
|
||||
interface AppLoadContext {
|
||||
VALUE_FROM_EXPRESS: string;
|
||||
}
|
||||
}
|
||||
|
||||
export const app = express();
|
||||
|
||||
if (!process.env.DATABASE_URL) throw new Error("DATABASE_URL is required");
|
||||
|
||||
const client = postgres(process.env.DATABASE_URL);
|
||||
const db = drizzle(client, { schema });
|
||||
app.use((_, __, next) => DatabaseContext.run(db, next));
|
||||
|
||||
app.use(
|
||||
createRequestHandler({
|
||||
build: () => import("virtual:react-router/server-build"),
|
||||
getLoadContext() {
|
||||
return {
|
||||
VALUE_FROM_EXPRESS: "Hello from Express",
|
||||
};
|
||||
},
|
||||
}),
|
||||
);
|
||||
Reference in New Issue
Block a user