8000 first build to js and then compile · lassejlv/postgres_http@99fb1dd · GitHub
[go: up one dir, main page]

Skip to content

Commit

Permalink
first build to js and then compile
Browse files Browse the repository at this point in the history
  • Loading branch information
lassejlv committed Dec 11, 2024
1 parent 2a35ff8 commit 99fb1dd
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 20 deletions.
1 change: 1 addition & 0 deletions 8000 .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
action.toml
33 changes: 33 additions & 0 deletions .github/workflows/build_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Build and Push Docker Image

on:
push:
branches: [ "development" ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: |
lassejlv/postgres_http:beta
15 changes: 0 additions & 15 deletions Dockerfile

This file was deleted.

16 changes: 14 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ import { logger } from 'hono/logger'
import { bearerAuth } from 'hono/bearer-auth'
import { cors } from 'hono/cors'

// Imported helper routes
import findFirst from './routes/findFirst'
import findMany from './routes/findMany'

const databaseUrl = process.env.DATABASE_URL
if (!databaseUrl) throw new Error('DATABASE_URL is required')

export const pool = new Pool({
connectionString: process.env.DATABASE_URL,
connectionString: databaseUrl,
// connection timeout = 1 minute
connectionTimeoutMillis: 60 * 1000,
})
Expand All @@ -18,7 +25,7 @@ const token = process.env.API_KEY;
if (!token) throw new Error('API_KEY is required')

app.use(logger())
app.use("*", cors({ origin: "*" }))
app.use("*", cors())
app.use("*", bearerAuth({ token }))


Expand All @@ -27,6 +34,11 @@ const schema = z.object({
args: z.array(z.any()).optional(),
})

app.basePath("/helpers")
.route("/findFirst", findFirst)
.route("/findMany", findMany)


app.post('/query', zValidator('json', schema), async (c) => {
try {
const { query, args } = c.req.valid('json')
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"module": "index.ts",
"type": "module",
"scripts": {
"build": "bun build --compile --minify --sourcemap index.ts --outfile ./dist/server",
"compile": "bun build --compile --minify --sourcemap dist/js/index.js --outfile ./dist/server",
"build": "bun build --target=bun index.ts --outdir ./dist/js",
"dev": "bun --watch index.ts",
"start": "./dist/server"
},
Expand Down
27 changes: 27 additions & 0 deletions routes/findFirst/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { zValidator } from "@hono/zod-validator";
import { Hono } from "hono";
import { schema } from "./schema";
import { pool } from "../..";




const router = new Hono()


router.post("/", zValidator("json", schema), async (c) => {

try {
const { table, where } = c.req.valid("json")

const query = `SELECT * FROM ${table} WHERE ${where} LIMIT 1`;
const result = await pool.query(query)

return c.json(result)
} catch (e: any) {
return c.json({ error: e.message }, 400)
}
})


export default router;
6 changes: 6 additions & 0 deletions routes/findFirst/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { z } from "zod";

export const schema = z.object({
table: z.string(),
where: z.any().optional(),
})
8C40 4 changes: 2 additions & 2 deletions routes/findMany/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { findManySchema } from "./schema";

const router = new Hono();

router.get("/", zValidator("query", findManySchema), async (c) => {
router.post("/", zValidator("json", findManySchema), async (c) => {
try {
const { table, where, limit } = c.req.valid("query")
const { table, where, limit } = c.req.valid("json")

const query = `SELECT * FROM ${table} WHERE ${where} LIMIT ${limit}`;
const result = await pool.query(query);
Expand Down

0 comments on commit 99fb1dd

Please sign in to comment.
0