Skip to content

Commit c307777

Browse files
committed
feat: update .env.example and add Caddyfile
1 parent b035de1 commit c307777

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed

.env.example

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
OLLAMA_API_ENDPOINT=""
2-
PUBLIC_API_ENDPOINT="$OLLAMA_API_ENDPOINT"
1+
PUBLIC_API_ENDPOINT="http://localhost:11434/api"
2+
3+
OLLAMA_API_ID='my-api-token'
4+
OLLAMA_API_TOKEN='xxxxxxxxxxxxxxxx'
5+
# generated by passing the token to `caddy hash-password`
6+
OLLAMA_API_TOKEN_DIGEST='$2a$14$iyyuawykR92xTHNR9lWzfu.uCct/9/xUPX3zBqLqrjAu0usNRPbyi'

Caddyfile.localhost

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Run with
2+
# caddy run --envfile ./example.env --config ./Caddyfile.localhost
3+
#
4+
# This is configured for
5+
# - Automatic HTTPS (even for localhost)
6+
# - Reverse Proxying to Ollama API Base URL (http://localhost:11434/api)
7+
# - CORS
8+
# - HTTP Basic Auth API Tokens (uncomment basicauth section)
9+
10+
11+
# CORS Preflight (OPTIONS) + Request (GET, POST, PATCH, PUT, DELETE)
12+
(cors-api) {
13+
@match-cors-api-preflight method OPTIONS
14+
handle @match-cors-api-preflight {
15+
header {
16+
Access-Control-Allow-Origin "{http.request.header.origin}"
17+
Access-Control-Allow-Methods "GET, POST, PUT, PATCH, DELETE, OPTIONS"
18+
Access-Control-Allow-Headers "Origin, Accept, Authorization, Content-Type, X-Requested-With"
19+
Access-Control-Allow-Credentials "true"
20+
Access-Control-Max-Age "3600"
21+
defer
22+
}
23+
respond "" 204
24+
}
25+
26+
@match-cors-api-request {
27+
not {
28+
header Origin "{http.request.scheme}://{http.request.host}"
29+
}
30+
header Origin "{http.request.header.origin}"
31+
}
32+
handle @match-cors-api-request {
33+
header {
34+
Access-Control-Allow-Origin "{http.request.header.origin}"
35+
Access-Control-Allow-Methods "GET, POST, PUT, PATCH, DELETE, OPTIONS"
36+
Access-Control-Allow-Headers "Origin, Accept, Authorization, Content-Type, X-Requested-With"
37+
Access-Control-Allow-Credentials "true"
38+
Access-Control-Max-Age "3600"
39+
defer
40+
}
41+
}
42+
}
43+
44+
# replace localhost with example.com or whatever
45+
localhost {
46+
## HTTP Basic Auth
47+
## (uncomment to enable)
48+
# basicauth {
49+
# # see .example.env for how to generate tokens
50+
# {env.OLLAMA_API_ID} {env.OLLAMA_API_TOKEN_DIGEST}
51+
# }
52+
53+
handle /api/* {
54+
# Comment to disable CORS
55+
import cors-api
56+
57+
reverse_proxy localhost:11434
58+
}
59+
60+
# Same-Origin Static Web Server
61+
file_server {
62+
root ./build/
63+
}
64+
}

0 commit comments

Comments
 (0)