Skip to content

Commit

Permalink
Add rate limit to isochrone calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuckal777 committed Dec 16, 2023
1 parent f416d0a commit 882c7f5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
8 changes: 7 additions & 1 deletion Caddyfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
https://localhost:443

root * /usr/share/caddy
reverse_proxy /api/* http://server:8080
route /api/* {
# global rate limit
rate_limit {host} 100r/m
# rate limit per "client"
rate_limit {remote.host} 25r/m
reverse_proxy http://server:8080
}
encode gzip
file_server {
precompressed br
Expand Down
6 changes: 5 additions & 1 deletion fastreach-ui/src/lib/IsochroneConfig.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@
});
if (res.status !== 200) {
error = `HTTP request failed, status code: ${res.status}`;
if (res.status === 429) {
error = "Please try again later.";
} else {
error = `HTTP request failed, status code: ${res.status}.`;
}
return;
}
const result = (await res.json()) as IsochroneResponse;
Expand Down
8 changes: 6 additions & 2 deletions ui.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
FROM node:18-alpine as build
FROM node:18-alpine as ui-build
WORKDIR /app/fastreach-ui
COPY . /app
RUN npm install && npm run build

FROM caddy:2.7-builder-alpine AS caddy-build
RUN xcaddy build --with github.com/RussellLuo/caddy-ext/ratelimit

FROM caddy:2.7-alpine
COPY --from=build /app/fastreach-ui/dist /usr/share/caddy
COPY --from=caddy-build /usr/bin/caddy /usr/bin/caddy
COPY --from=ui-build /app/fastreach-ui/dist /usr/share/caddy

0 comments on commit 882c7f5

Please sign in to comment.