Working reverse proxy

This commit is contained in:
Julien Valverdé
2024-07-17 01:43:21 +02:00
parent 2497aaa236
commit 2daf60faf3
4 changed files with 67 additions and 10 deletions

40
Caddyfile Normal file
View File

@@ -0,0 +1,40 @@
(reverse_proxy_headers) {
header_up Host {upstream_hostport}
}
http://* {
@websockets {
header Connection *Upgrade*
header Upgrade websocket
}
handle @websockets {
reverse_proxy http://server {
import reverse_proxy_headers
}
}
handle /rpc* {
reverse_proxy http://server {
import reverse_proxy_headers
}
}
handle {
reverse_proxy http://webui {
import reverse_proxy_headers
}
}
}
http://server.* {
reverse_proxy http://server {
import reverse_proxy_headers
}
}
http://webui.* {
reverse_proxy http://webui {
import reverse_proxy_headers
}
}

View File

@@ -2,34 +2,44 @@ x-service-base: &service-base
user: ${UID:?UID missing}:${GID:?GID missing} user: ${UID:?UID missing}:${GID:?GID missing}
tty: true tty: true
x-service-bun: &service-bun
<<: *service-base
image: oven/bun
x-volume-app: &volume-app ./:/app/ x-volume-app: &volume-app ./:/app/
x-env-base: &env-base
TZ: ${TZ:?TZ missing}
services: services:
reverse-proxy:
container_name: reverse-proxy
image: caddy:latest
ports:
- ${PORT:?PORT missing}:80
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
environment:
<<: *env-base
server: server:
<<: *service-bun <<: *service-base
container_name: server container_name: server
image: oven/bun:latest
volumes: volumes:
- *volume-app - *volume-app
working_dir: /app/packages/server working_dir: /app/packages/server
ports:
- 80:80
env_file: .env env_file: .env
environment: environment:
<<: *env-base
NODE_ENV: development NODE_ENV: development
HTTP_PORT: 80
entrypoint: ["bun", "src/index.ts"] entrypoint: ["bun", "src/index.ts"]
webui: webui:
<<: *service-bun <<: *service-base
container_name: webui container_name: webui
image: oven/bun:latest
volumes: volumes:
- *volume-app - *volume-app
working_dir: /app/packages/webui working_dir: /app/packages/webui
environment: environment:
<<: *env-base
NODE_ENV: development NODE_ENV: development
entrypoint: ["bun", "dev"] entrypoint: ["bun", "dev"]

View File

@@ -1,6 +1,6 @@
import { BunRuntime } from "@effect/platform-bun" import { BunRuntime } from "@effect/platform-bun"
import { Todo } from "@todo-tests/common/data" import { Todo } from "@todo-tests/common/data"
import { Duration, Effect, Layer, Match, Option } from "effect" import { Duration, Effect, Layer, Logger, Match, Option } from "effect"
import { ServerConfig } from "./ServerConfig" import { ServerConfig } from "./ServerConfig"
import { Services } from "./Services" import { Services } from "./Services"
import { ExpressApp } from "./http/ExpressApp" import { ExpressApp } from "./http/ExpressApp"
@@ -105,5 +105,6 @@ const main = Effect.gen(function*() {
BunRuntime.runMain(main.pipe( BunRuntime.runMain(main.pipe(
Effect.provide(Services.Dev), Effect.provide(Services.Dev),
Effect.provide(Logger.structured),
Effect.scoped, Effect.scoped,
)) ))

View File

@@ -6,7 +6,13 @@ import { defineConfig } from "vite"
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default defineConfig({
server: { server: {
host: true,
port: 80, port: 80,
hmr: {
host: "webui.localhost",
port: Number(process.env.PORT),
},
}, },
plugins: [ plugins: [