updated examples

This commit is contained in:
dswbx
2024-11-23 11:21:25 +01:00
parent 2433833ad0
commit f70e2b2e10
13 changed files with 74 additions and 64 deletions

BIN
bun.lockb

Binary file not shown.

View File

@@ -1,10 +1,9 @@
/*
// somehow causes types:build issues on app
// @ts-ignore somehow causes types:build issues on app
import type { CreateAppConfig } from "bknd";
// @ts-ignore somehow causes types:build issues on app
import { serve } from "bknd/adapter/bun";
const root = "../../node_modules/bknd/dist";
// this is optional, if omitted, it uses an in-memory database
const config = {
connection: {
type: "libsql",
@@ -16,8 +15,12 @@ const config = {
Bun.serve({
port: 1337,
fetch: serve(config, root)
fetch: serve(
config,
// this is only required to run inside the same workspace
// leave blank if you're running this from a different project
"../../node_modules/bknd/dist"
)
});
console.log("Server running at http://localhost:1337");
s*/

View File

@@ -1,7 +1,7 @@
{
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"target": "ESNext",
"target": "ES2022",
"module": "ESNext",
"jsx": "react-jsx",
"allowJs": true,

View File

@@ -8,15 +8,13 @@ export default serve(
connection: {
type: "libsql",
config: {
url: env.DB_URL,
authToken: env.DB_TOKEN
url: "http://localhost:8080"
}
}
}),
onBuilt: async (app) => {
app.modules.server.get("/", (c) => c.json({ hello: "world" }));
},
setAdminHtml: true
app.modules.server.get("/hello", (c) => c.json({ hello: "world" }));
}
},
manifest
);

View File

@@ -4,6 +4,8 @@
"private": true,
"scripts": {
"dev": "next dev",
"db": "turso dev --db-file test.db",
"db:check": "sqlite3 test.db \"PRAGMA wal_checkpoint(FULL);\"",
"build": "next build",
"start": "next start",
"lint": "next lint"

View File

@@ -9,51 +9,7 @@ export default serve({
connection: {
type: "libsql",
config: {
url: process.env.DB_URL!,
authToken: process.env.DB_AUTH_TOKEN!
}
}
}); /*
let app: App;
async function getApp() {
if (!app) {
app = App.create({
connection: {
type: "libsql",
config: {
url: process.env.DB_URL!,
authToken: process.env.DB_AUTH_TOKEN!
url: "http://localhost:8080"
}
}
});
await app.build();
}
return app;
}
function getCleanRequest(req: Request) {
// clean search params from "route" attribute
const url = new URL(req.url);
url.searchParams.delete("route");
return new Request(url.toString(), {
method: req.method,
headers: req.headers,
body: req.body
});
}
export default async (req: Request, requestContext: any) => {
//console.log("here");
if (!app) {
app = await getApp();
}
//const app = await getApp();
const request = getCleanRequest(req);
//console.log("url", req.url);
//console.log("req", req);
return app.fetch(request, process.env);
};
//export default handle(app.server.getInstance())
*/

BIN
examples/nextjs/test.db Normal file

Binary file not shown.

20
examples/node/index.js Normal file
View File

@@ -0,0 +1,20 @@
import { serve } from "bknd/adapter/node";
// this is optional, if omitted, it uses an in-memory database
/** @type {import("bknd").CreateAppConfig} */
const config = {
connection: {
type: "libsql",
config: {
url: "http://localhost:8080"
}
}
};
serve(config, {
relativeDistPath: "../../node_modules/bknd/dist",
port: 1337,
listener: ({ port }) => {
console.log(`Server is running on http://localhost:${port}`);
}
});

View File

@@ -0,0 +1,20 @@
{
"name": "node",
"module": "index.js",
"type": "module",
"private": true,
"scripts": {
"start": "node index.js",
"dev": "tsx --watch index.js"
},
"dependencies": {
"bknd": "workspace:*",
"@hono/node-server": "^1.13.3"
},
"devDependencies": {
"tsx": "^4.19.2"
},
"peerDependencies": {
"typescript": "^5.0.0"
}
}

View File

@@ -12,7 +12,7 @@ export default function AdminPage() {
return (
<Suspense>
<Admin withProvider />
<Admin />
</Suspense>
);
}

View File

@@ -6,7 +6,8 @@
"scripts": {
"build": "remix vite:build",
"dev": "remix vite:dev",
"lint": "eslint --ignore-path .gitignore --cache --cache-location ./node_modules/.cache/eslint .",
"db": "turso dev --db-file test.db",
"db:check": "sqlite3 test.db \"PRAGMA wal_checkpoint(FULL);\"",
"start": "remix-serve ./build/server/index.js",
"typecheck": "tsc"
},

BIN
examples/remix/test.db Normal file

Binary file not shown.

View File

@@ -7,10 +7,7 @@
<legend>Params</legend>
<div>
<label for="entity">Entity:</label>
<select id="entity">
<option value="todos">Todos</option>
<option value="notes">Notes</option>
</select>
<select id="entity"></select>
</div>
<div>
<div>
@@ -29,6 +26,19 @@
</fieldset>
<script>
fetch("/api/system/config/data")
.then(res => res.json())
.then(({ config: { entities} }) => {
console.log(entities);
const entity = document.getElementById('entity');
Object.entries(entities).forEach(([name, config]) => {
const option = document.createElement('option');
option.value = name;
option.innerText = config.label ?? name;
entity.appendChild(option);
});
});
const btn = document.getElementById('btn');
const query = document.getElementById('query');
query.onblur = function(e) {