@bbki.ng/backend 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # backend
2
+
3
+ ## 0.0.2
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ ```txt
2
+ npm install
3
+ npm run dev
4
+ ```
5
+
6
+ ```txt
7
+ npm run deploy
8
+ ```
9
+
10
+ [For generating/synchronizing types based on your Worker configuration run](https://developers.cloudflare.com/workers/wrangler/commands/#types):
11
+
12
+ ```txt
13
+ npm run cf-typegen
14
+ ```
15
+
16
+ Pass the `CloudflareBindings` as generics when instantiation `Hono`:
17
+
18
+ ```ts
19
+ // src/index.ts
20
+ const app = new Hono<{ Bindings: CloudflareBindings }>()
21
+ ```
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@bbki.ng/backend",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "dependencies": {
6
+ "hono": "^4.10.7"
7
+ },
8
+ "devDependencies": {
9
+ "@cloudflare/workers-types": "4.20251128.0",
10
+ "wrangler": "^4.4.0"
11
+ },
12
+ "scripts": {
13
+ "dev": "wrangler dev",
14
+ "deploy": "wrangler deploy --minify",
15
+ "cf-typegen": "wrangler types --env-interface CloudflareBindings"
16
+ }
17
+ }
package/src/index.ts ADDED
@@ -0,0 +1,45 @@
1
+ import { Hono } from "hono";
2
+ import type { D1Database } from "@cloudflare/workers-types";
3
+ import { cors } from "hono/cors";
4
+
5
+ type Bindings = {
6
+ DB: D1Database;
7
+ };
8
+
9
+ const app = new Hono<{ Bindings: Bindings }>();
10
+
11
+ app.get("/", (c) => {
12
+ return c.text("Hello Hono!");
13
+ });
14
+
15
+ app.post(
16
+ "/comment/add",
17
+ cors({
18
+ origin: ["https://bbki.ng"],
19
+ }),
20
+ async (c) => {
21
+ const { articleId, author, content } = await c.req.json();
22
+
23
+ try {
24
+ let { results } = await c.env.DB.prepare(
25
+ "INSERT INTO comment (article_id, author, content, created_at) VALUES (?, ?, ?, ?);",
26
+ )
27
+ .bind(articleId, author, content, new Date().toISOString())
28
+ .run();
29
+
30
+ return c.json({
31
+ status: "success",
32
+ message: "Comment added successfully",
33
+ results,
34
+ });
35
+ } catch (error: any) {
36
+ return c.json({
37
+ status: "error",
38
+ message: "Failed to add comment",
39
+ error: error.message,
40
+ });
41
+ }
42
+ },
43
+ );
44
+
45
+ export default app;
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Bundler",
6
+ "strict": true,
7
+ "skipLibCheck": true,
8
+ "lib": [
9
+ "ESNext"
10
+ ],
11
+ "jsx": "react-jsx",
12
+ "jsxImportSource": "hono/jsx"
13
+ },
14
+ }
package/wrangler.jsonc ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "$schema": "node_modules/wrangler/config-schema.json",
3
+ "name": "backend",
4
+ "main": "src/index.ts",
5
+ "compatibility_date": "2025-12-01",
6
+ // "compatibility_flags": [
7
+ // "nodejs_compat"
8
+ // ],
9
+ // "vars": {
10
+ // "MY_VAR": "my-variable"
11
+ // },
12
+ // "kv_namespaces": [
13
+ // {
14
+ // "binding": "MY_KV_NAMESPACE",
15
+ // "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
16
+ // }
17
+ // ],
18
+ // "r2_buckets": [
19
+ // {
20
+ // "binding": "MY_BUCKET",
21
+ // "bucket_name": "my-bucket"
22
+ // }
23
+ // ],
24
+ "d1_databases": [
25
+ {
26
+ "binding": "DB",
27
+ "database_name": "bbki.ng",
28
+ "database_id": "e938a347-b3be-4d60-9217-52f209ab7bb4",
29
+ },
30
+ ],
31
+ // "ai": {
32
+ // "binding": "AI"
33
+ // },
34
+ // "observability": {
35
+ // "enabled": true,
36
+ // "head_sampling_rate": 1
37
+ // }
38
+ }