Skip to content

Commit 8df7c3a

Browse files
committed
Merge branch 'main' into tech-sort-and-versions
2 parents 13cb046 + b312132 commit 8df7c3a

29 files changed

+2607
-1945
lines changed

.github/workflows/dependabot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
if: github.event.pull_request.user.login == 'dependabot[bot]' && github.repository == 'HTTPArchive/tech-report-apis'
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v5
14+
- uses: actions/checkout@v6
1515
- run: |
1616
cd src
1717
npm ci

.github/workflows/deployment.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
test:
1414
runs-on: ubuntu-latest
1515
steps:
16-
- uses: actions/checkout@v5
16+
- uses: actions/checkout@v6
1717
- run: |
1818
cd src
1919
npm ci
@@ -27,9 +27,9 @@ jobs:
2727
run:
2828
working-directory: ./terraform/dev
2929
steps:
30-
- uses: actions/checkout@v5
30+
- uses: actions/checkout@v6
3131
- name: Google Cloud Auth
32-
uses: 'google-github-actions/auth@v2'
32+
uses: 'google-github-actions/auth@v3'
3333
with:
3434
project_id: 'httparchive'
3535
credentials_json: ${{ env.PIPELINE_SA_KEY }}
@@ -72,9 +72,9 @@ jobs:
7272
run:
7373
working-directory: ./terraform/prod
7474
steps:
75-
- uses: actions/checkout@v5
75+
- uses: actions/checkout@v6
7676
- name: Google Cloud Auth
77-
uses: 'google-github-actions/auth@v2'
77+
uses: 'google-github-actions/auth@v3'
7878
with:
7979
project_id: 'httparchive'
8080
credentials_json: ${{ env.PIPELINE_SA_KEY }}

README.md

Lines changed: 32 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This is an HTTP Archive Reporting API that provides reporting data via various e
66

77
### Prerequisites
88

9-
- Node.js 18+
9+
- Node.js 22+
1010
- npm
1111
- Google Cloud account with necessary permissions
1212
- Set environment variables:
@@ -22,15 +22,14 @@ This is an HTTP Archive Reporting API that provides reporting data via various e
2222
npm run start
2323
```
2424

25-
The API will be available at <http://localhost:3000>
25+
The API will be available at <http://localhost:8080>
2626

2727
## API Endpoints
2828

2929
- **CORS Enabled**: Cross-origin requests are supported
3030
- **Cache Headers**: 6-hour cache control for static data
3131
- **Health Check**: GET `/` returns health status
3232
- **RESTful API**: All endpoints follow REST conventions
33-
- **Backend caching**: Some responses are cached on the backend for 1 hours to improve latency
3433

3534
### `GET /`
3635

@@ -501,51 +500,49 @@ Returns a JSON object with the following schema:
501500
]
502501
```
503502
504-
### `GET /cache-stats`
503+
### `GET /static/*`
505504
506-
Provides statistics about the API's cache.
505+
Proxy endpoint to serve files from the private Google Cloud Storage bucket. The request path after `/v1/static/` maps directly to the GCS object path.
507506
508-
```bash
509-
curl --request GET \
510-
--url 'https://{{HOST}}/v1/cache-stats'
511-
```
507+
#### Static File Features
512508
513-
Returns a JSON object with the following schema:
509+
- **Conditional Requests**: Supports `If-None-Match` header for cache validation (returns 304 if unchanged)
510+
- **Content Type Detection**: Automatically detects MIME type based on file extension
511+
- **Streaming**: Files are streamed directly from GCS for efficient memory usage
512+
- **ETag Support**: Returns ETag header for cache validation
514513
515-
```json
516-
{
517-
"cache_hits": 12345,
518-
"cache_misses": 6789,
519-
"last_cleared": "2023-10-01T12:00:00Z"
520-
}
521-
```
514+
#### Supported File Types
522515
523-
### `POST /v1/cache-reset`
516+
| Extension | MIME Type |
517+
|-----------|-----------|
518+
| `.json` | `application/json` |
519+
| `.js` | `application/javascript` |
520+
| `.png` | `image/png` |
521+
| `.svg` | `image/svg+xml` |
522+
| `.csv` | `text/csv` |
523+
| `.pdf` | `application/pdf` |
524524
525-
Resets all caches in the API. This endpoint requires a POST request.
525+
#### Static File Response
526526
527527
```bash
528-
curl --request POST \
529-
--url 'https://{{HOST}}/v1/cache-reset'
528+
curl --request GET \
529+
--url 'https://{{HOST}}/v1/static/reports/2023/example.json'
530530
```
531531
532-
Returns a JSON object with the following schema:
532+
Returns the file content with appropriate headers:
533533
534-
```json
535-
{
536-
"success": true,
537-
"message": "All caches have been reset",
538-
"before": {
539-
"queryCache": 150,
540-
"dateCache": 12
541-
},
542-
"after": {
543-
"queryCache": 0,
544-
"dateCache": 0
545-
}
546-
}
534+
```http
535+
Content-Type: application/json
536+
ETag: "abc123..."
537+
Content-Length: 1234
547538
```
548539
540+
#### Error Responses
541+
542+
- **400 Bad Request**: Invalid file path (e.g., contains `..` or `//`)
543+
- **404 Not Found**: File does not exist in the bucket
544+
- **500 Internal Server Error**: Failed to retrieve or stream the file
545+
549546
## Testing
550547
551548
```bash
@@ -667,34 +664,4 @@ Response:
667664
}
668665
```
669666
670-
## Cache Stats Private Endpoint
671-
672-
The Cache Stats private endpoint provides information about the API's cache performance, including cache hits, misses, and the last time the cache was cleared. This endpoint is useful for monitoring and debugging cache behavior.
673-
674-
```bash
675-
curl "https://tech-report-api-dev-226352634162.us-central1.run.app/v1/cache-stats" \
676-
-H "Authorization: bearer $(gcloud auth print-identity-token)"
677-
```
678-
679-
Returns a JSON object with the following schema:
680667
681-
```json
682-
{
683-
"queryCache": {
684-
"total": 3220,
685-
"valid": 2437,
686-
"expired": 783,
687-
"ttl": 3600000
688-
},
689-
"dateCache": {
690-
"total": 4,
691-
"valid": 4,
692-
"expired": 0,
693-
"ttl": 3600000
694-
},
695-
"config": {
696-
"maxCacheSize": 5000,
697-
"cleanupStrategy": "size-based-lru"
698-
}
699-
}
700-
```

src/.dockerignore

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
node_modules
1+
node_modules/
22
npm-debug.log
33
.git
44
.gitignore
55
.env
66
.nyc_output
7-
coverage
87
*.md
98
.DS_Store
109
cloudbuild.yaml
11-
__tests__
12-
coverage
10+
__tests__/
11+
coverage/

src/Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ COPY package*.json ./
99
# Install dependencies (this layer will be cached unless package files change)
1010
RUN npm ci --only=production --quiet --no-fund --no-audit && npm cache clean --force
1111

12-
ENV DATABASE=tech-report-api-prod
13-
1412
# Copy source code
1513
COPY . .
1614

17-
CMD ["node", "index.js"]
15+
# Cloud Run expects the container to listen on PORT (default 8080)
16+
ENV PORT=8080
17+
18+
# Use Functions Framework to serve the app
19+
CMD ["npx", "functions-framework", "--target=app"]

0 commit comments

Comments
 (0)