13 Commits

Author SHA1 Message Date
6861867e2e chore(deps): update dependency eslint to v8.57.0 2024-04-17 00:50:40 +00:00
Lee
edf96e4e64 Merge pull request 'chore(deps): update dependency tsup to v8' (#9) from renovate/tsup-8.x into master
All checks were successful
Publish Docker Images / docker (push) Successful in 2m17s
Reviewed-on: #9
2023-11-19 11:23:27 +00:00
72e3a62236 chore(deps): update dependency tsup to v8 2023-11-19 11:01:09 +00:00
ddfbb60b25 7
All checks were successful
Publish Docker Images / docker (push) Successful in 1m21s
2023-11-17 10:03:09 +00:00
eb116c06cd use boolean field for cached status
All checks were successful
Publish Docker Images / docker (push) Successful in 1m24s
2023-11-17 09:44:07 +00:00
74f5832a8a add cache status to all requests
All checks were successful
Publish Docker Images / docker (push) Successful in 1m22s
2023-11-17 09:31:06 +00:00
bde1fc4572 cleanup
All checks were successful
Publish Docker Images / docker (push) Successful in 1m32s
2023-11-17 09:17:12 +00:00
Lee
c0c0a3d5b0 Merge pull request 'fix(deps): update dependency mongoose to v8' (#8) from renovate/mongoose-8.x into master
All checks were successful
Publish Docker Images / docker (push) Successful in 1m44s
Reviewed-on: #8
2023-11-17 09:06:07 +00:00
Lee
095f13791a Merge pull request 'chore(deps): update docker/login-action action to v3' (#6) from renovate/docker-login-action-3.x into master
Some checks failed
Publish Docker Images / docker (push) Has been cancelled
Reviewed-on: #6
2023-11-17 09:06:00 +00:00
Lee
e8acd3b831 Merge pull request 'chore(deps): update docker/build-push-action action to v5' (#5) from renovate/docker-build-push-action-5.x into master
Some checks are pending
Publish Docker Images / docker (push) Waiting to run
Reviewed-on: #5
2023-11-17 09:05:55 +00:00
49e97bb415 fix(deps): update dependency mongoose to v8 2023-11-16 18:01:52 +00:00
bca3e284b2 chore(deps): update docker/login-action action to v3 2023-11-16 13:01:20 +00:00
82c1b85c08 chore(deps): update docker/build-push-action action to v5 2023-11-16 12:01:22 +00:00
6 changed files with 406 additions and 382 deletions

View File

@ -14,7 +14,7 @@ jobs:
uses: actions/checkout@v4
- name: Login to Repo
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.REPO_USERNAME }}
password: ${{ secrets.REPO_TOKEN }}
@ -26,7 +26,7 @@ jobs:
run: pnpm run build
- name: Build and Push (Node)
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
push: true
context: .
@ -34,7 +34,7 @@ jobs:
tags: fascinated/proxy:node-latest
- name: Build and Push (Proxy)
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
push: true
context: .

View File

@ -4,9 +4,6 @@ FROM fascinated/docker-images:node-pnpm-latest AS base
# Make sure you update this Dockerfile, the Dockerfile in the web workspace and copy that over to Dockerfile in the docs.
FROM base AS builder
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
RUN apk update
# Set working directory
WORKDIR /app
RUN pnpm install -g turbo

View File

@ -20,6 +20,6 @@
"utils": "workspace:*",
"node-cache": "^5.1.2",
"@influxdata/influxdb-client": "^1.33.2",
"mongoose": "^7.6.3"
"mongoose": "^8.0.0"
}
}

View File

@ -84,14 +84,12 @@ async function logRequestToDatabase({
const point = new Point("proxy")
.tag("type", "request")
.tag("node", nodeId)
.booleanField("cached", cached ? true : false)
.stringField("url", url)
.intField("status", status)
.timestamp(Date.now());
if (cached) {
point.tag("cached", "true");
}
if (time) {
point.intField("time", time as number);
point.intField("time", time);
}
try {
InfluxWriteApi.writePoint(point);
@ -125,18 +123,16 @@ export default class ProxyRoute extends Route {
try {
const cachedRequest = cache.get<CachedRequest>(url);
if (cachedRequest) {
res
.status(cachedRequest.status)
.set(cachedRequest.headers)
.json(cachedRequest.data);
log(cachedRequest.nodeId, url, cachedRequest.status, true);
logRequestToDatabase({
nodeId: cachedRequest.nodeId,
const { status, headers, data, nodeId } = cachedRequest;
res.status(status).set(headers).json(data);
log(nodeId, url, status, true);
return logRequestToDatabase({
nodeId: nodeId,
url,
status: cachedRequest.status,
status: status,
cached: true,
});
return;
}
const node = nodeManager.getRandomNode();
@ -150,29 +146,30 @@ export default class ProxyRoute extends Route {
const before = Date.now();
const response = await node.fetch(url);
const nodeId = response.headers["x-proxy-node"];
const data = response.data;
const { status, headers, data } = response;
if (response.status === 500) {
res.status(500).json(RouteMessages.internalServerError(data));
return;
}
log(nodeId, url, response.status, Date.now() - before);
log(nodeId, url, status, Date.now() - before);
logRequestToDatabase({
nodeId,
url,
status: response.status,
status: status,
time: Date.now() - before,
cached: false,
});
cache.set(url, {
nodeId: nodeId,
status: response.status,
headers: response.headers,
status: status,
headers: headers,
data: data,
} as CachedRequest);
// Send the response to the client
res.status(response.status).set(response.headers).send(data);
res.status(status).set(headers).send(data);
} catch (ex: any) {
res.status(500).json(RouteMessages.internalServerError(ex.message || ex));
}

View File

@ -17,11 +17,11 @@
"nodemon": "^3.0.1",
"prettier": "^3.0.3",
"tsconfig": "workspace:*",
"tsup": "^7.2.0",
"tsup": "^8.0.0",
"turbo": "latest"
},
"dependencies": {
"@types/express": "^4.17.21",
"mongoose": "7.6.3"
"mongoose": "8.0.1"
}
}

738
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff