commit
549423d867
6 changed files with 1111 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -8,6 +8,7 @@ pnpm-debug.log*
|
|||
lerna-debug.log*
|
||||
|
||||
**/node_modules
|
||||
*.env
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
|
|
|||
26
proxy-service/Dockerfile
Normal file
26
proxy-service/Dockerfile
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
# syntax=docker/dockerfile:1
|
||||
|
||||
# Use the official Node.js image as the base image
|
||||
ARG NODE_VERSION=22.13.1
|
||||
FROM node:${NODE_VERSION}-slim AS base
|
||||
|
||||
# Set the working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Install curl, ping, and netstat
|
||||
RUN apt-get update && apt-get install -y curl iputils-ping net-tools
|
||||
|
||||
COPY . .
|
||||
RUN npm install
|
||||
|
||||
# Install dependencies using npm ci for deterministic builds
|
||||
# RUN --mount=type=cache,target=/root/.npm npm ci --production
|
||||
|
||||
# Copy the application source code
|
||||
COPY --link . .
|
||||
|
||||
# Expose the application port
|
||||
EXPOSE 8080
|
||||
|
||||
# Define the command to run the application
|
||||
CMD ["node", "server.js"]
|
||||
42
proxy-service/fly.toml
Normal file
42
proxy-service/fly.toml
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
# fly.toml app configuration file generated for proxy-service on 2025-04-30T16:36:47-07:00
|
||||
#
|
||||
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
|
||||
#
|
||||
|
||||
app = 'proxy-service'
|
||||
primary_region = 'sea'
|
||||
|
||||
[build]
|
||||
|
||||
[env]
|
||||
PORT = '8080'
|
||||
|
||||
[http_service]
|
||||
internal_port = 8080
|
||||
force_https = true
|
||||
auto_stop_machines = 'stop'
|
||||
auto_start_machines = true
|
||||
min_machines_running = 0
|
||||
processes = ['app']
|
||||
|
||||
[[services]]
|
||||
protocol = 'tcp'
|
||||
internal_port = 8080
|
||||
|
||||
[[services.ports]]
|
||||
port = 80
|
||||
handlers = ['http']
|
||||
|
||||
[[services.ports]]
|
||||
port = 443
|
||||
handlers = ['tls', 'http']
|
||||
|
||||
[[services.tcp_checks]]
|
||||
interval = '10s'
|
||||
timeout = '2s'
|
||||
grace_period = '5s'
|
||||
|
||||
[[vm]]
|
||||
memory = '1gb'
|
||||
cpu_kind = 'shared'
|
||||
cpus = 1
|
||||
1001
proxy-service/package-lock.json
generated
Normal file
1001
proxy-service/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
7
proxy-service/package.json
Normal file
7
proxy-service/package.json
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"express": "^5.1.0",
|
||||
"http-proxy": "^1.18.1",
|
||||
"http-proxy-middleware": "^3.0.5"
|
||||
}
|
||||
}
|
||||
34
proxy-service/server.js
Normal file
34
proxy-service/server.js
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
const express = require('express');
|
||||
const { createProxyMiddleware } = require('http-proxy-middleware');
|
||||
|
||||
const app = express();
|
||||
const port = 8080;
|
||||
|
||||
// Middleware to handle dynamic IPv6 proxying
|
||||
app.use('/:ipv6', (req, res, next) => {
|
||||
const ipv6 = req.params.ipv6;
|
||||
|
||||
// Validate or sanitize the IPv6 if needed
|
||||
const targetUrl = `http://[${ipv6}]:8000`;
|
||||
console.log(`Proxying request to: ${targetUrl}`);
|
||||
|
||||
// Create and attach the proxy middleware *once per request*
|
||||
const proxy = createProxyMiddleware({
|
||||
target: targetUrl,
|
||||
changeOrigin: true,
|
||||
logLevel: 'debug',
|
||||
// pathRewrite: {
|
||||
// [`^/${ipv6}`]: '/', // Send to root of the target
|
||||
// },
|
||||
onError(err, req, res) {
|
||||
console.error('Proxy error:', err.message);
|
||||
res.status(502).send('Bad Gateway: Failed to connect to target');
|
||||
}
|
||||
});
|
||||
|
||||
return proxy(req, res, next);
|
||||
});
|
||||
|
||||
app.listen(port, '0.0.0.0', () => {
|
||||
console.log(`Proxy server listening on http://0.0.0.0:${port}`);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue