Compare commits
7 Commits
c0c0a3d5b0
...
renovate/t
Author | SHA1 | Date | |
---|---|---|---|
3b90247116 | |||
edf96e4e64 | |||
72e3a62236 | |||
ddfbb60b25 | |||
eb116c06cd | |||
74f5832a8a | |||
bde1fc4572 |
@ -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
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
"nodemon": "^3.0.1",
|
||||
"prettier": "^3.0.3",
|
||||
"tsconfig": "workspace:*",
|
||||
"tsup": "^7.2.0",
|
||||
"tsup": "^8.0.0",
|
||||
"turbo": "latest"
|
||||
},
|
||||
"dependencies": {
|
||||
|
555
pnpm-lock.yaml
generated
555
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user