Skip to content

Commit 558fd7e

Browse files
committed
setup Caddy with API at /api
1 parent 1a0a5a0 commit 558fd7e

5 files changed

Lines changed: 48 additions & 12 deletions

File tree

deployment/Caddyfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
${DOMAIN:localhost} {
2+
handle /api/* {
3+
reverse_proxy http://localhost:${NODE_PORT:8080}
4+
}
5+
6+
handle {
7+
reverse_proxy http://localhost:${FRONTEND_PORT:3000}
8+
9+
}
10+
}

deployment/compose.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
services:
2+
caddy:
3+
image: caddy:2.10-alpine
4+
restart: unless-stopped
5+
ports:
6+
- "80:80"
7+
- "443:443"
8+
- "443:443/udp"
9+
volumes:
10+
- ./Caddyfile:/etc/caddy/Caddyfile
11+
- caddy_data:/data
12+
- caddy_config:/config
13+
environment:
14+
- FRONTEND_PORT=${FRONTEND_PORT}
15+
- NODE_PORT=${NODE_PORT}
16+
- DOMAIN=${DOMAIN}
17+
18+
volumes:
19+
caddy_data:
20+
caddy_config:

deployment/docker-autostart.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ set -e
44
source .env
55
if [ $WHISPER_SERVICE_CUDA = 'true' ]; then
66
echo Stopping any currently running services
7-
sudo docker compose -f ./compose_cuda.yaml down
7+
sudo docker compose -f compose.yaml -f ./compose_cuda.yaml down
88

99
echo Starting services with CUDA enabled for whisper-service
10-
sudo docker compose -f ./compose_cuda.yaml up -d
10+
sudo docker compose -f compose.yaml -f ./compose_cuda.yaml up -d
1111
else
1212
echo Stopping any currently running services
13-
sudo docker compose -f ./compose_cpu.yaml down
13+
sudo docker compose -f compose.yaml -f ./compose_cpu.yaml down
1414

1515
echo Starting services without CUDA
16-
sudo docker compose -f ./compose_cpu.yaml up -d
16+
sudo docker compose -f compose.yaml -f ./compose_cpu.yaml up -d
1717
fi
1818

1919
until [ "$(curl --max-time 1 -s -w '%{http_code}' -o /dev/null "${SCRIBEAR_URL}")" -eq 200 ]

deployment/template.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
NODE_ENV="production"
22
LOG_LEVEL="info"
3+
DOMAIN="dcl-1265-05.cs.illinois.edu"
34

45
#### Host and port API webserver should listen on
56
CORS_ORIGIN='*'

node-server/src/server/create_server.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import Fastify, {type FastifyInstance} from 'fastify';
1+
import Fastify, { type FastifyInstance } from 'fastify';
22
import fastifyCors from '@fastify/cors';
3-
import type {ConfigType} from '../shared/config/config_schema.js';
4-
import type {Logger} from '../shared/logger/logger.js';
3+
import type { ConfigType } from '../shared/config/config_schema.js';
4+
import type { Logger } from '../shared/logger/logger.js';
55
import TranscriptionEngine from './services/transcription_engine.js';
66
import fastifyWebsocket from '@fastify/websocket';
77
import websocketHandler from './routes/websocket_handler.js';
@@ -30,7 +30,7 @@ declare module 'fastify' {
3030
* @returns created fastify server
3131
*/
3232
export default function createServer(config: ConfigType, logger: Logger) {
33-
const fastify = Fastify({loggerInstance: logger}) as unknown as FastifyInstance;
33+
const fastify = Fastify({ loggerInstance: logger }) as unknown as FastifyInstance;
3434

3535
fastify.register(fastifyWebsocket);
3636

@@ -49,10 +49,15 @@ export default function createServer(config: ConfigType, logger: Logger) {
4949
fastify.decorate('tokenService', new TokenService(config, logger));
5050
fastify.decorate('authenticationService', new AuthenticationService(config, fastify.tokenService));
5151

52-
// Register routes
53-
fastify.register(websocketHandler);
54-
fastify.register(accessTokenHandler);
55-
fastify.register(healthcheckHandler);
52+
fastify.register(
53+
async (api, _options) => {
54+
api.register(websocketHandler,);
55+
api.register(accessTokenHandler);
56+
api.register(healthcheckHandler);
57+
58+
},
59+
{ prefix: "/api" },
60+
);
5661

5762
return fastify;
5863
}

0 commit comments

Comments
 (0)