mirror of
https://github.com/Lapikud/tipilan.git
synced 2026-09-22 07:17:41 +00:00
Migrate to proxy, remome syslink
This commit is contained in:
5
.github/workflows/build.yml
vendored
5
.github/workflows/build.yml
vendored
@@ -26,10 +26,5 @@ jobs:
|
|||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: bun install
|
run: bun install
|
||||||
|
|
||||||
- name: Ensure symlink to database before Drizzle migrations
|
|
||||||
run: |
|
|
||||||
rm -rf $GITHUB_WORKSPACE/data
|
|
||||||
ln -s ~/data $GITHUB_WORKSPACE/data
|
|
||||||
|
|
||||||
- name: Build project
|
- name: Build project
|
||||||
run: bun --bun run build
|
run: bun --bun run build
|
||||||
|
|||||||
@@ -2,5 +2,26 @@ import { drizzle } from "drizzle-orm/bun-sqlite";
|
|||||||
import { Database } from "bun:sqlite";
|
import { Database } from "bun:sqlite";
|
||||||
import * as schema from "./schema/schema";
|
import * as schema from "./schema/schema";
|
||||||
|
|
||||||
const sqlite = new Database("data/tipilan.db");
|
let database: any = null;
|
||||||
export const db = drizzle(sqlite, { schema });
|
|
||||||
|
function getDatabase() {
|
||||||
|
if (!database) {
|
||||||
|
const sqlite = new Database("data/tipilan.db");
|
||||||
|
database = drizzle(sqlite, { schema });
|
||||||
|
}
|
||||||
|
|
||||||
|
return database;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const db: any = new Proxy({}, {
|
||||||
|
get(_target, property, receiver) {
|
||||||
|
const instance = getDatabase() as unknown as Record<PropertyKey, unknown>;
|
||||||
|
const value = Reflect.get(instance, property, receiver);
|
||||||
|
|
||||||
|
if (typeof value === "function") {
|
||||||
|
return value.bind(instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { routing } from "./i18n/routing";
|
|||||||
|
|
||||||
const handleI18nRouting = createMiddleware(routing);
|
const handleI18nRouting = createMiddleware(routing);
|
||||||
|
|
||||||
export default function middleware(request: NextRequest) {
|
export default function proxy(request: NextRequest) {
|
||||||
const response = handleI18nRouting(request);
|
const response = handleI18nRouting(request);
|
||||||
|
|
||||||
const location = response.headers.get("location");
|
const location = response.headers.get("location");
|
||||||
Reference in New Issue
Block a user