Compare commits
15 Commits
57d3aa3266
...
renovate/d
Author | SHA1 | Date | |
---|---|---|---|
b30773d8df | |||
edf96e4e64 | |||
72e3a62236 | |||
ddfbb60b25 | |||
eb116c06cd | |||
74f5832a8a | |||
bde1fc4572 | |||
c0c0a3d5b0 | |||
095f13791a | |||
e8acd3b831 | |||
785eb27452 | |||
49e97bb415 | |||
bca3e284b2 | |||
82c1b85c08 | |||
b8669f4128 |
@ -11,10 +11,10 @@ jobs:
|
|||||||
container: fascinated/docker-images:node-pnpm-latest
|
container: fascinated/docker-images:node-pnpm-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Login to Repo
|
- name: Login to Repo
|
||||||
uses: docker/login-action@v2
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.REPO_USERNAME }}
|
username: ${{ secrets.REPO_USERNAME }}
|
||||||
password: ${{ secrets.REPO_TOKEN }}
|
password: ${{ secrets.REPO_TOKEN }}
|
||||||
@ -26,7 +26,7 @@ jobs:
|
|||||||
run: pnpm run build
|
run: pnpm run build
|
||||||
|
|
||||||
- name: Build and Push (Node)
|
- name: Build and Push (Node)
|
||||||
uses: docker/build-push-action@v4
|
uses: docker/build-push-action@v5
|
||||||
with:
|
with:
|
||||||
push: true
|
push: true
|
||||||
context: .
|
context: .
|
||||||
@ -34,7 +34,7 @@ jobs:
|
|||||||
tags: fascinated/proxy:node-latest
|
tags: fascinated/proxy:node-latest
|
||||||
|
|
||||||
- name: Build and Push (Proxy)
|
- name: Build and Push (Proxy)
|
||||||
uses: docker/build-push-action@v4
|
uses: docker/build-push-action@v5
|
||||||
with:
|
with:
|
||||||
push: true
|
push: true
|
||||||
context: .
|
context: .
|
||||||
|
@ -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.
|
# 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
|
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
|
# Set working directory
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
RUN pnpm install -g turbo
|
RUN pnpm install -g turbo
|
||||||
|
@ -20,6 +20,6 @@
|
|||||||
"utils": "workspace:*",
|
"utils": "workspace:*",
|
||||||
"node-cache": "^5.1.2",
|
"node-cache": "^5.1.2",
|
||||||
"@influxdata/influxdb-client": "^1.33.2",
|
"@influxdata/influxdb-client": "^1.33.2",
|
||||||
"mongoose": "^7.6.3"
|
"mongoose": "^8.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,14 +84,12 @@ async function logRequestToDatabase({
|
|||||||
const point = new Point("proxy")
|
const point = new Point("proxy")
|
||||||
.tag("type", "request")
|
.tag("type", "request")
|
||||||
.tag("node", nodeId)
|
.tag("node", nodeId)
|
||||||
|
.booleanField("cached", cached ? true : false)
|
||||||
.stringField("url", url)
|
.stringField("url", url)
|
||||||
.intField("status", status)
|
.intField("status", status)
|
||||||
.timestamp(Date.now());
|
.timestamp(Date.now());
|
||||||
if (cached) {
|
|
||||||
point.tag("cached", "true");
|
|
||||||
}
|
|
||||||
if (time) {
|
if (time) {
|
||||||
point.intField("time", time as number);
|
point.intField("time", time);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
InfluxWriteApi.writePoint(point);
|
InfluxWriteApi.writePoint(point);
|
||||||
@ -125,18 +123,16 @@ export default class ProxyRoute extends Route {
|
|||||||
try {
|
try {
|
||||||
const cachedRequest = cache.get<CachedRequest>(url);
|
const cachedRequest = cache.get<CachedRequest>(url);
|
||||||
if (cachedRequest) {
|
if (cachedRequest) {
|
||||||
res
|
const { status, headers, data, nodeId } = cachedRequest;
|
||||||
.status(cachedRequest.status)
|
|
||||||
.set(cachedRequest.headers)
|
res.status(status).set(headers).json(data);
|
||||||
.json(cachedRequest.data);
|
log(nodeId, url, status, true);
|
||||||
log(cachedRequest.nodeId, url, cachedRequest.status, true);
|
return logRequestToDatabase({
|
||||||
logRequestToDatabase({
|
nodeId: nodeId,
|
||||||
nodeId: cachedRequest.nodeId,
|
|
||||||
url,
|
url,
|
||||||
status: cachedRequest.status,
|
status: status,
|
||||||
cached: true,
|
cached: true,
|
||||||
});
|
});
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const node = nodeManager.getRandomNode();
|
const node = nodeManager.getRandomNode();
|
||||||
@ -150,29 +146,30 @@ export default class ProxyRoute extends Route {
|
|||||||
const before = Date.now();
|
const before = Date.now();
|
||||||
const response = await node.fetch(url);
|
const response = await node.fetch(url);
|
||||||
const nodeId = response.headers["x-proxy-node"];
|
const nodeId = response.headers["x-proxy-node"];
|
||||||
const data = response.data;
|
const { status, headers, data } = response;
|
||||||
|
|
||||||
if (response.status === 500) {
|
if (response.status === 500) {
|
||||||
res.status(500).json(RouteMessages.internalServerError(data));
|
res.status(500).json(RouteMessages.internalServerError(data));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
log(nodeId, url, response.status, Date.now() - before);
|
log(nodeId, url, status, Date.now() - before);
|
||||||
logRequestToDatabase({
|
logRequestToDatabase({
|
||||||
nodeId,
|
nodeId,
|
||||||
url,
|
url,
|
||||||
status: response.status,
|
status: status,
|
||||||
time: Date.now() - before,
|
time: Date.now() - before,
|
||||||
|
cached: false,
|
||||||
});
|
});
|
||||||
cache.set(url, {
|
cache.set(url, {
|
||||||
nodeId: nodeId,
|
nodeId: nodeId,
|
||||||
status: response.status,
|
status: status,
|
||||||
headers: response.headers,
|
headers: headers,
|
||||||
data: data,
|
data: data,
|
||||||
} as CachedRequest);
|
} as CachedRequest);
|
||||||
|
|
||||||
// Send the response to the client
|
// 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) {
|
} catch (ex: any) {
|
||||||
res.status(500).json(RouteMessages.internalServerError(ex.message || ex));
|
res.status(500).json(RouteMessages.internalServerError(ex.message || ex));
|
||||||
}
|
}
|
||||||
|
@ -17,11 +17,11 @@
|
|||||||
"nodemon": "^3.0.1",
|
"nodemon": "^3.0.1",
|
||||||
"prettier": "^3.0.3",
|
"prettier": "^3.0.3",
|
||||||
"tsconfig": "workspace:*",
|
"tsconfig": "workspace:*",
|
||||||
"tsup": "^7.2.0",
|
"tsup": "^8.0.0",
|
||||||
"turbo": "latest"
|
"turbo": "latest"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/express": "^4.17.21",
|
"@types/express": "^4.17.21",
|
||||||
"mongoose": "7.6.3"
|
"mongoose": "8.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
604
pnpm-lock.yaml
generated
604
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user