mirror of
https://github.com/linsa-io/linsa.git
synced 2026-04-28 11:17:20 +02:00
.
This commit is contained in:
36
packages/worker/src/index.ts
Normal file
36
packages/worker/src/index.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { Hono } from "hono"
|
||||
import { cors } from "hono/cors"
|
||||
|
||||
// Create a new Hono app
|
||||
const app = new Hono()
|
||||
|
||||
// Enable CORS for all routes
|
||||
app.use("/*", cors())
|
||||
|
||||
// Health check endpoint
|
||||
app.get("/health", (c) => {
|
||||
return c.json({ status: "ok", message: "Worker is running!" })
|
||||
})
|
||||
|
||||
// Root endpoint
|
||||
app.get("/", (c) => {
|
||||
return c.json({
|
||||
message: "Welcome to the Cloudflare Worker API",
|
||||
endpoints: {
|
||||
health: "/health",
|
||||
api: "/api/v1",
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
// Example API endpoint
|
||||
app.get("/api/v1/hello", (c) => {
|
||||
const name = c.req.query("name") || "World"
|
||||
return c.json({ message: `Hello, ${name}!` })
|
||||
})
|
||||
|
||||
// Export the Hono app as default (handles HTTP requests)
|
||||
export default app
|
||||
|
||||
// Export the RPC worker for RPC calls via service bindings
|
||||
export { WorkerRpc } from "./rpc"
|
||||
Reference in New Issue
Block a user