Skip to content

Commit

Permalink
Merge pull request #790 from Shelf-nu/hono-deploy-fix
Browse files Browse the repository at this point in the history
Hono deploy fix
  • Loading branch information
DonKoko authored Feb 26, 2024
2 parents 6e92e45 + 2ff1407 commit 2cb9d0f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 61 deletions.
19 changes: 5 additions & 14 deletions app/routes/healthcheck.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
// learn more: https://fly.io/docs/reference/configuration/#services-http_checks
import type { LoaderFunctionArgs } from "@remix-run/node";
import { json } from "@remix-run/node";

import { db } from "~/database";

export async function loader({ request }: LoaderFunctionArgs) {
const host =
request.headers.get("X-Forwarded-Host") ?? request.headers.get("host");

export async function loader() {
try {
const url = new URL("/", `http://${host}`);
// if we can connect to the database and make a simple query
// and make a HEAD request to ourselves, then we're good.
await Promise.all([
db.user.findFirst(),
fetch(url.toString(), { method: "HEAD" }).then((r) => {
if (!r.ok) return Promise.reject(r);
}),
]);
return new Response("OK");
await db.user.findFirst();
return json({ status: "OK" });
} catch (error: unknown) {
// eslint-disable-next-line no-console
console.log("healthcheck ❌", { error });
return new Response("ERROR", { status: 500 });
return json({ status: "ERROR" }, { status: 500 });
}
}
87 changes: 41 additions & 46 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -1,51 +1,46 @@
app = "shelf-webapp"

primary_region = "ams"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []
kill_timeout = "5s"
swap_size_mb = 512

[experimental]
auto_rollback = true

[deploy]
strategy = "bluegreen"

[env]
PORT = "8080"
NODE_ENV = "production"
NODE_ENV = "production"
PORT = "8080"

[[services.ports]]
handlers = ["http"]
port = 80
force_https = true

[[services.ports]]
handlers = ["tls", "http"]
port = 443

[http_service]
internal_port = 8080
force_https = true
auto_stop_machines = false
auto_start_machines = false
min_machines_running = 1
processes = ["app"]

[http_service.concurrency]
type = "requests"
soft_limit = 100
hard_limit = 125

[[http_service.checks]]
grace_period = "5s"
interval = "10s"
method = "GET"
timeout = "2s"
path = "/healthcheck"
protocol = "http"

[experimental]
allowed_public_ports = []
auto_rollback = true
cmd = "start.sh"
entrypoint = "sh"

[[services]]
internal_port = 8080
processes = ["app"]
protocol = "tcp"
script_checks = []

[services.concurrency]
hard_limit = 125
soft_limit = 100
type = "connections"

[[services.ports]]
handlers = ["http"]
port = 80
force_https = true

[[services.ports]]
handlers = ["tls", "http"]
port = 443

[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
restart_limit = 0
timeout = "2s"

[[services.http_checks]]
interval = "10s"
grace_period = "5s"
method = "get"
path = "/healthcheck"
protocol = "http"
timeout = "2s"
tls_skip_verify = false
[services.http_checks.headers]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"setup:seed": "prisma db seed",
"reset:db": "prisma migrate reset",
"reset:db:staging": "dotenv -e .env.staging -- prisma migrate reset",
"start": "remix-serve build/index.js",
"start": "NODE_ENV=production node build/index.js",
"start:ci": "dotenv -- remix-serve build",
"test": "echo test",
"test:cov": "vitest --coverage",
Expand Down

0 comments on commit 2cb9d0f

Please sign in to comment.