@seip/blue-bird 0.7.2 → 0.7.4
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/AGENTS.md +32 -0
- package/README.md +23 -0
- package/core/cache.js +6 -0
- package/docker/nginx.conf +23 -0
- package/index.js +1 -1
- package/package.json +1 -1
package/AGENTS.md
CHANGED
|
@@ -206,4 +206,36 @@ const stats = await connection.query("SELECT COUNT(*) as cnt FROM logs", [], { c
|
|
|
206
206
|
const newUserId = await connection.query("INSERT INTO users (name) VALUES (?)", ["Alice"]);
|
|
207
207
|
```
|
|
208
208
|
|
|
209
|
+
## 11. Nginx Proxy Caching
|
|
210
|
+
|
|
211
|
+
In production, Nginx caches Astro page responses for 10 seconds. Requests with an active session cookie (`auth`) or `Authorization` header bypass the cache to ensure dynamic page personalized output.
|
|
212
|
+
|
|
213
|
+
### Disabling Cache
|
|
214
|
+
|
|
215
|
+
To disable Nginx proxy caching, comment out the `proxy_cache` directives in `docker/nginx.conf`:
|
|
216
|
+
|
|
217
|
+
```nginx
|
|
218
|
+
# proxy_cache astro_cache;
|
|
219
|
+
# proxy_cache_valid 200 302 10s;
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Caching API routes
|
|
223
|
+
|
|
224
|
+
To cache specific GET API routes at the proxy layer (which is faster and consumes less resources than Node/Redis query caching), define a specific location block in `docker/nginx.conf` before the generic `/api/` routing rule:
|
|
225
|
+
|
|
226
|
+
```nginx
|
|
227
|
+
location /api/cached-endpoint {
|
|
228
|
+
limit_req zone=bluebird_limit burst=20 nodelay;
|
|
229
|
+
set $upstream_target http://app:3000;
|
|
230
|
+
proxy_pass $upstream_target;
|
|
231
|
+
proxy_http_version 1.1;
|
|
232
|
+
proxy_set_header Connection "";
|
|
233
|
+
proxy_set_header Host $host;
|
|
234
|
+
|
|
235
|
+
proxy_cache astro_cache;
|
|
236
|
+
proxy_cache_valid 200 10s;
|
|
237
|
+
add_header X-Cache-Status $upstream_cache_status;
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
209
241
|
_This file can be retrieved by intelligent agents reading its absolute physical path during reasoning._
|
package/README.md
CHANGED
|
@@ -237,6 +237,29 @@ const newId = await connection.query("INSERT INTO users (name) VALUES (?)", ["Jo
|
|
|
237
237
|
|
|
238
238
|
---
|
|
239
239
|
|
|
240
|
+
### 8. Nginx Proxy Caching
|
|
241
|
+
|
|
242
|
+
Nginx reverse proxy is preconfigured with a page cache zone (`astro_cache`) that stores public page outputs (Astro SSR/SSG) for 10 seconds.
|
|
243
|
+
- **Cache Bypass:** Requests with an `auth` cookie or `Authorization` header automatically bypass the cache to ensure dynamic page outputs.
|
|
244
|
+
- **Disabling:** Caching can be turned off in `docker/nginx.conf` by commenting out the `proxy_cache` directives.
|
|
245
|
+
- **Caching API routes:** If you want Nginx to cache GET endpoints from `/api/` directly (which is much faster than Node query/redis caching), add a matching location block inside `docker/nginx.conf` before the generic `/api/` block:
|
|
246
|
+
```nginx
|
|
247
|
+
location /api/cached-stats {
|
|
248
|
+
limit_req zone=bluebird_limit burst=20 nodelay;
|
|
249
|
+
set $upstream_target http://app:3000;
|
|
250
|
+
proxy_pass $upstream_target;
|
|
251
|
+
proxy_http_version 1.1;
|
|
252
|
+
proxy_set_header Connection "";
|
|
253
|
+
proxy_set_header Host $host;
|
|
254
|
+
|
|
255
|
+
proxy_cache astro_cache;
|
|
256
|
+
proxy_cache_valid 200 10s;
|
|
257
|
+
add_header X-Cache-Status $upstream_cache_status;
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
240
263
|
## 🐳 Docker CLI Workflow
|
|
241
264
|
|
|
242
265
|
Blue Bird comes with a built-in Docker CLI wrapper that handles both local development database bootstrapping and full-stack VPS production deployments.
|
package/core/cache.js
CHANGED
|
@@ -31,6 +31,12 @@ async function initRedis() {
|
|
|
31
31
|
redisClient.on("error", () => {
|
|
32
32
|
isRedisConnected = false;
|
|
33
33
|
});
|
|
34
|
+
redisClient.on("ready", () => {
|
|
35
|
+
isRedisConnected = true;
|
|
36
|
+
});
|
|
37
|
+
redisClient.on("connect", () => {
|
|
38
|
+
isRedisConnected = true;
|
|
39
|
+
});
|
|
34
40
|
await redisClient.connect();
|
|
35
41
|
isRedisConnected = true;
|
|
36
42
|
} catch (err) {
|
package/docker/nginx.conf
CHANGED
|
@@ -46,6 +46,8 @@ http {
|
|
|
46
46
|
|
|
47
47
|
limit_req_zone $binary_remote_addr zone=bluebird_limit:10m rate=10r/s;
|
|
48
48
|
|
|
49
|
+
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=astro_cache:10m max_size=1g inactive=60m use_temp_path=off;
|
|
50
|
+
|
|
49
51
|
server {
|
|
50
52
|
listen 80;
|
|
51
53
|
server_name localhost;
|
|
@@ -61,6 +63,18 @@ http {
|
|
|
61
63
|
try_files $uri @node_app;
|
|
62
64
|
}
|
|
63
65
|
|
|
66
|
+
location /api/ {
|
|
67
|
+
limit_req zone=bluebird_limit burst=20 nodelay;
|
|
68
|
+
set $upstream_target http://app:3000;
|
|
69
|
+
proxy_pass $upstream_target;
|
|
70
|
+
proxy_http_version 1.1;
|
|
71
|
+
proxy_set_header Connection "";
|
|
72
|
+
proxy_set_header Host $host;
|
|
73
|
+
proxy_set_header X-Real-IP $remote_addr;
|
|
74
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
75
|
+
proxy_set_header X-Forwarded-Proto $scheme;
|
|
76
|
+
}
|
|
77
|
+
|
|
64
78
|
location /_astro/ {
|
|
65
79
|
expires max;
|
|
66
80
|
add_header Cache-Control "public, max-age=31536000, immutable";
|
|
@@ -78,6 +92,15 @@ http {
|
|
|
78
92
|
proxy_set_header X-Real-IP $remote_addr;
|
|
79
93
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
80
94
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
95
|
+
|
|
96
|
+
proxy_cache astro_cache;
|
|
97
|
+
proxy_cache_valid 200 302 10s;
|
|
98
|
+
proxy_cache_valid 404 1m;
|
|
99
|
+
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
|
|
100
|
+
proxy_cache_lock on;
|
|
101
|
+
proxy_cache_bypass $cookie_auth $http_authorization;
|
|
102
|
+
proxy_no_cache $cookie_auth $http_authorization;
|
|
103
|
+
add_header X-Cache-Status $upstream_cache_status;
|
|
81
104
|
}
|
|
82
105
|
}
|
|
83
106
|
}
|
package/index.js
CHANGED
package/package.json
CHANGED