claude-code-limiter-server 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Caddyfile +12 -0
- package/Dockerfile +57 -0
- package/LICENSE +21 -0
- package/bin/server.js +51 -0
- package/docker-compose.yml +46 -0
- package/package.json +27 -0
- package/src/dashboard/css/style.css +1374 -0
- package/src/dashboard/index.html +118 -0
- package/src/dashboard/js/app.js +1650 -0
- package/src/dashboard/js/charts.js +388 -0
- package/src/dashboard/js/ws.js +172 -0
- package/src/server/db.js +484 -0
- package/src/server/index.js +100 -0
- package/src/server/routes/admin-api.js +386 -0
- package/src/server/routes/hook-api.js +312 -0
- package/src/server/services/auth.js +174 -0
- package/src/server/services/limiter.js +226 -0
- package/src/server/services/usage.js +87 -0
- package/src/server/ws.js +74 -0
package/Caddyfile
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Caddyfile for claude-code-limiter
|
|
2
|
+
# Set the DOMAIN env var for auto-HTTPS, or leave unset for localhost.
|
|
3
|
+
#
|
|
4
|
+
# With a real domain (auto-HTTPS):
|
|
5
|
+
# DOMAIN=limiter.example.com docker compose up
|
|
6
|
+
#
|
|
7
|
+
# LAN-only (no HTTPS):
|
|
8
|
+
# docker compose up (defaults to localhost)
|
|
9
|
+
|
|
10
|
+
{$DOMAIN:localhost} {
|
|
11
|
+
reverse_proxy limiter:3000
|
|
12
|
+
}
|
package/Dockerfile
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Multi-stage build for claude-code-limiter server
|
|
2
|
+
# Runs the Express server with SQLite, serves dashboard on same port
|
|
3
|
+
|
|
4
|
+
# --- Stage 1: Install dependencies ---
|
|
5
|
+
FROM node:20-slim AS deps
|
|
6
|
+
|
|
7
|
+
WORKDIR /app
|
|
8
|
+
|
|
9
|
+
# Install build tools for better-sqlite3 native compilation
|
|
10
|
+
RUN apt-get update && \
|
|
11
|
+
apt-get install -y --no-install-recommends python3 make g++ && \
|
|
12
|
+
rm -rf /var/lib/apt/lists/*
|
|
13
|
+
|
|
14
|
+
COPY package.json package-lock.json* ./
|
|
15
|
+
RUN npm ci --omit=dev
|
|
16
|
+
|
|
17
|
+
# --- Stage 2: Production image ---
|
|
18
|
+
FROM node:20-slim
|
|
19
|
+
|
|
20
|
+
# Install curl for healthcheck + minimal runtime deps for better-sqlite3
|
|
21
|
+
RUN apt-get update && \
|
|
22
|
+
apt-get install -y --no-install-recommends curl && \
|
|
23
|
+
rm -rf /var/lib/apt/lists/*
|
|
24
|
+
|
|
25
|
+
WORKDIR /app
|
|
26
|
+
|
|
27
|
+
# Copy node_modules (with compiled native modules) from deps stage
|
|
28
|
+
COPY --from=deps /app/node_modules ./node_modules
|
|
29
|
+
COPY package.json ./
|
|
30
|
+
COPY src/ ./src/
|
|
31
|
+
COPY bin/ ./bin/
|
|
32
|
+
|
|
33
|
+
# Create data directory for SQLite volume
|
|
34
|
+
RUN mkdir -p /data
|
|
35
|
+
|
|
36
|
+
# Create non-root user for security
|
|
37
|
+
RUN groupadd --system limiter && \
|
|
38
|
+
useradd --system --gid limiter --home /app limiter && \
|
|
39
|
+
chown -R limiter:limiter /app /data
|
|
40
|
+
|
|
41
|
+
# Environment
|
|
42
|
+
ENV NODE_ENV=production
|
|
43
|
+
ENV DATA_DIR=/data
|
|
44
|
+
|
|
45
|
+
EXPOSE 3000
|
|
46
|
+
|
|
47
|
+
# SQLite database persisted via volume
|
|
48
|
+
VOLUME ["/data"]
|
|
49
|
+
|
|
50
|
+
# Healthcheck: verify the server responds
|
|
51
|
+
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
|
52
|
+
CMD curl -f http://localhost:3000/health || exit 1
|
|
53
|
+
|
|
54
|
+
# Run as non-root
|
|
55
|
+
USER limiter
|
|
56
|
+
|
|
57
|
+
CMD ["node", "bin/server.js"]
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Basha
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/bin/server.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
// Server entry point for Docker CMD and `npm start`.
|
|
6
|
+
// Handles graceful shutdown on SIGTERM/SIGINT.
|
|
7
|
+
|
|
8
|
+
const app = require('../src/server/index.js');
|
|
9
|
+
|
|
10
|
+
const port = parseInt(process.env.PORT || '3000', 10);
|
|
11
|
+
|
|
12
|
+
console.log(`[server] Starting claude-code-limiter server...`);
|
|
13
|
+
console.log(`[server] NODE_ENV=${process.env.NODE_ENV || 'development'}`);
|
|
14
|
+
console.log(`[server] DATA_DIR=${process.env.DATA_DIR || '(default)'}`);
|
|
15
|
+
|
|
16
|
+
app.start(port);
|
|
17
|
+
|
|
18
|
+
// ---- Graceful shutdown ----
|
|
19
|
+
|
|
20
|
+
function shutdown(signal) {
|
|
21
|
+
console.log(`\n[server] Received ${signal}. Shutting down gracefully...`);
|
|
22
|
+
|
|
23
|
+
// Close the HTTP server so no new connections are accepted
|
|
24
|
+
if (app.server) {
|
|
25
|
+
app.server.close(() => {
|
|
26
|
+
console.log('[server] HTTP server closed.');
|
|
27
|
+
process.exit(0);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Force exit after 10 seconds if connections don't drain
|
|
31
|
+
setTimeout(() => {
|
|
32
|
+
console.error('[server] Forcing shutdown after timeout.');
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}, 10000).unref();
|
|
35
|
+
} else {
|
|
36
|
+
process.exit(0);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
|
41
|
+
process.on('SIGINT', () => shutdown('SIGINT'));
|
|
42
|
+
|
|
43
|
+
// Catch unhandled errors so the container doesn't silently die
|
|
44
|
+
process.on('unhandledRejection', (err) => {
|
|
45
|
+
console.error('[server] Unhandled rejection:', err);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
process.on('uncaughtException', (err) => {
|
|
49
|
+
console.error('[server] Uncaught exception:', err);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
version: "3.8"
|
|
2
|
+
|
|
3
|
+
services:
|
|
4
|
+
limiter:
|
|
5
|
+
build:
|
|
6
|
+
context: .
|
|
7
|
+
dockerfile: Dockerfile
|
|
8
|
+
container_name: claude-limiter
|
|
9
|
+
restart: unless-stopped
|
|
10
|
+
environment:
|
|
11
|
+
- NODE_ENV=production
|
|
12
|
+
- PORT=3000
|
|
13
|
+
- DATA_DIR=/data
|
|
14
|
+
- ADMIN_PASSWORD=${ADMIN_PASSWORD:-changeme}
|
|
15
|
+
- JWT_SECRET=${JWT_SECRET:-}
|
|
16
|
+
volumes:
|
|
17
|
+
- limiter-data:/data
|
|
18
|
+
networks:
|
|
19
|
+
- limiter-net
|
|
20
|
+
expose:
|
|
21
|
+
- "3000"
|
|
22
|
+
|
|
23
|
+
caddy:
|
|
24
|
+
image: caddy:2
|
|
25
|
+
container_name: claude-limiter-caddy
|
|
26
|
+
restart: unless-stopped
|
|
27
|
+
ports:
|
|
28
|
+
- "80:80"
|
|
29
|
+
- "443:443"
|
|
30
|
+
volumes:
|
|
31
|
+
- ./Caddyfile:/etc/caddy/Caddyfile:ro
|
|
32
|
+
- caddy-data:/data
|
|
33
|
+
- caddy-config:/config
|
|
34
|
+
networks:
|
|
35
|
+
- limiter-net
|
|
36
|
+
depends_on:
|
|
37
|
+
- limiter
|
|
38
|
+
|
|
39
|
+
volumes:
|
|
40
|
+
limiter-data:
|
|
41
|
+
caddy-data:
|
|
42
|
+
caddy-config:
|
|
43
|
+
|
|
44
|
+
networks:
|
|
45
|
+
limiter-net:
|
|
46
|
+
driver: bridge
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "claude-code-limiter-server",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Dashboard server for claude-code-limiter",
|
|
5
|
+
"main": "src/server/index.js",
|
|
6
|
+
"bin": { "claude-limiter-server": "./bin/server.js" },
|
|
7
|
+
"scripts": { "start": "node bin/server.js" },
|
|
8
|
+
"files": ["bin/", "src/", "Dockerfile", "docker-compose.yml", "Caddyfile", "LICENSE"],
|
|
9
|
+
"engines": { "node": ">=18.0.0" },
|
|
10
|
+
"author": "howincodes",
|
|
11
|
+
"contributors": [
|
|
12
|
+
"farisbasha"
|
|
13
|
+
],
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"express": "^4.21.0",
|
|
16
|
+
"better-sqlite3": "^11.0.0",
|
|
17
|
+
"ws": "^8.18.0",
|
|
18
|
+
"bcryptjs": "^2.4.3",
|
|
19
|
+
"jsonwebtoken": "^9.0.2",
|
|
20
|
+
"uuid": "^10.0.0"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/howincodes/claude-code-limiter"
|
|
25
|
+
},
|
|
26
|
+
"license": "MIT"
|
|
27
|
+
}
|