move to vercel

This commit is contained in:
2024-04-29 17:11:54 +02:00
parent 5220496061
commit 9aad68d451
11 changed files with 3062 additions and 83 deletions

13
.gitignore vendored
View File

@@ -1,10 +1,3 @@
node_modules
dist
.wrangler
.dev.vars
# Change them to your taste:
package-lock.json
yarn.lock
pnpm-lock.yaml
bun.lockb
.vercel
.env
node_modules

View File

@@ -1,8 +1,4 @@
```
npm install
npm run dev
```
```
npm run deploy
npm run start
```

View File

@@ -1,33 +1,33 @@
import { Context, Hono } from 'hono'
import { drizzle } from "drizzle-orm/libsql";
import { createClient } from "@libsql/client/web";
import * as schema from './db/schema'
import { createClient } from '@libsql/client';
import { IssueCommentEvent } from '@octokit/webhooks-types';
import { drizzle } from 'drizzle-orm/libsql';
import { Hono } from 'hono'
import { handle } from '@hono/node-server/vercel'
import { Octokit } from 'octokit';
import * as schema from '../db/schema.js'
const octokit = new Octokit({ auth: `personal-access-token123` });
export type Bindings = {
TURSO_URL: string,
TURSO_TOKEN: string,
GITHUB_API_TOKEN: string,
export const config = {
api: {
bodyParser: false,
},
}
const app = new Hono()
const turso = createClient({
url: process.env.TURSO_URL!,
authToken: process.env.TURSO_TOKEN!,
})
const octokit = new Octokit({ auth: process.env.GITHUB_API_TOKEN! });
const db = drizzle(turso, { schema })
app.get('/', async (c) => {
const { db } = importLibs(c)
const fetch = await db.insert(schema.rtmAuthor).values({
authorId: '1',
mergerId: '2',
}).execute()
return c.json(fetch.toJSON())
const app = new Hono().basePath('/api')
app.get('/', (c) => {
return c.json({ message: 'Hello Hono!' })
})
app.post('/ev/readyToMerge', async (c) => {
const body = await c.req.json() as IssueCommentEvent
const bodyUrl = body.issue.html_url.split('/')
const { db, octokit } = importLibs(c)
let isRTM = false
if (bodyUrl[bodyUrl.length - 2] !== 'pull')
@@ -58,12 +58,4 @@ app.post('/ev/readyToMerge', async (c) => {
return c.json({ ok: true })
})
export default app
function importLibs(c: Context) {
const turso = createClient({
url: c.env.TURSO_URL!,
authToken: c.env.TURSO_TOKEN!,
})
const octokit = new Octokit({ auth: c.env.GITHUB_API_TOKEN! });
return { db: drizzle(turso, { schema }), octokit: octokit };
}
export default handle(app)

View File

@@ -3,7 +3,7 @@ import * as dotenv from "dotenv";
dotenv.config();
export default {
schema: "./src/db/schema.ts",
schema: "./db/schema.ts",
out: "./drizzle/migrations",
driver: "turso",
dbCredentials: {

View File

@@ -1,23 +1,22 @@
{
"scripts": {
"dev": "wrangler dev src/index.ts",
"deploy": "wrangler deploy --minify src/index.ts",
"start": "vercel dev",
"deploy": "vercel",
"migrate": "drizzle-kit generate:sqlite && node --loader ts-node/esm src/db/migrate.ts"
},
"dependencies": {
"@hono/node-server": "^1.11.1",
"@libsql/client": "^0.6.0",
"@octokit/webhooks-types": "^7.5.1",
"drizzle-orm": "^0.30.9",
"hono": "^4.2.5",
"hono": "^4.2.9",
"octokit": "^3.2.0"
},
"type": "module",
"devDependencies": {
"@cloudflare/workers-types": "^4.20240403.0",
"dotenv": "^16.4.5",
"drizzle-kit": "^0.20.17",
"ts-node": "^10.9.2",
"typescript": "^5.4.5",
"wrangler": "^3.47.0"
}
"vercel": "^32.4.1"
},
"type": "module"
}

View File

@@ -2,15 +2,9 @@
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Bundler",
"moduleResolution": "node",
"esModuleInterop": true,
"skipLibCheck": true,
"strict": true,
"lib": [
"ESNext"
],
"types": [
"@cloudflare/workers-types"
],
"jsx": "react-jsx",
"jsxImportSource": "hono/jsx"
},
}

8
vercel.json Normal file
View File

@@ -0,0 +1,8 @@
{
"rewrites": [
{
"source": "/api/(.*)",
"destination": "/api"
}
]
}

View File

@@ -1,22 +0,0 @@
name = "sern-automata"
compatibility_date = "2023-12-01"
compatibility_flags = [ "nodejs_compat" ]
# [vars]
# MY_VAR = "my-variable"
# [[kv_namespaces]]
# binding = "MY_KV_NAMESPACE"
# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# [[r2_buckets]]
# binding = "MY_BUCKET"
# bucket_name = "my-bucket"
# [[d1_databases]]
# binding = "DB"
# database_name = "my-database"
# database_id = ""
# [ai]
# binding = "AI"

3019
yarn.lock Normal file

File diff suppressed because it is too large Load Diff