init
This commit is contained in:
commit
24b87d5ea2
|
@ -0,0 +1,11 @@
|
|||
node_modules/*
|
||||
# misc
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
|
@ -0,0 +1,77 @@
|
|||
import express from 'express';
|
||||
import multer from 'multer';
|
||||
import ws from 'ws';
|
||||
import EventEmitter from 'events';
|
||||
import cors from 'cors';
|
||||
|
||||
const upload = multer();
|
||||
const app = express();
|
||||
const port = process.env.PORT || 3000
|
||||
|
||||
const events = new EventEmitter();
|
||||
|
||||
app.use(cors());
|
||||
|
||||
app.get('/show-requests', ( _, res ) => {
|
||||
res.send('<!DOCTYPE html><HTML><head><title>REQUEST VIEWER</title></head><body><script src="/static-assets/web.js"></script><noscript><h1>This tool requires JavaScript</h1><br /></noscript>Please use developer console to see mirrored requests</body></HTML>');
|
||||
})
|
||||
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
app.use(upload.array());
|
||||
|
||||
app.use('/static-assets', express.static('web-static'));
|
||||
|
||||
app.use( (req, res) => {
|
||||
const data = {
|
||||
body: req.body,
|
||||
headers: req.headers,
|
||||
ip: req.ip,
|
||||
path: req.path,
|
||||
protocol: req.protocol,
|
||||
xhr: req.xhr,
|
||||
subdomains: req.subdomains,
|
||||
secure: req.secure,
|
||||
ips: req.ips,
|
||||
hostname: req.hostname,
|
||||
method: req.method,
|
||||
protocol: req.protocol,
|
||||
params: req.params,
|
||||
query: req.query,
|
||||
route: req.route,
|
||||
signedCookie: req.signedCookies,
|
||||
cookies: req.cookies,
|
||||
fresh: req.fresh,
|
||||
stale: req.stale,
|
||||
baseUrl: req.baseUrl,
|
||||
originalUrl: req.originalUrl
|
||||
}
|
||||
events.emit('request', JSON.stringify(data));
|
||||
console.log(JSON.stringify(data));
|
||||
res.send("<!DOCTYPE html><html><body><a href=\"/show-requests\">Request Viewer</a><html>");
|
||||
});
|
||||
|
||||
const wsServer = new ws.Server({ noServer: true });
|
||||
wsServer.on('connection', socket => {
|
||||
socket.on('message', message => {
|
||||
if ( message === "PING" ) {
|
||||
return socket.send("PONG");
|
||||
}
|
||||
if ( message === "TEST" ) {
|
||||
return socket.send("TEST");
|
||||
}
|
||||
console.log(message);
|
||||
});
|
||||
const handler = (e) => socket.send(e);
|
||||
events.on('request', handler);
|
||||
socket.onclose = () => events.off('request', handler);
|
||||
})
|
||||
|
||||
const server = app.listen(port, () => {
|
||||
console.log(`LISTENING AT http://localhost:${port}`);
|
||||
})
|
||||
server.on('upgrade', (request, socket, head) => {
|
||||
wsServer.handleUpgrade(request, socket, head, (socket) => {
|
||||
wsServer.emit('connection', socket, request);
|
||||
})
|
||||
})
|
|
@ -0,0 +1,7 @@
|
|||
applications:
|
||||
- name: OpenFN Bank - Request Mirror Server
|
||||
disk_quota: 1G
|
||||
instances: 1
|
||||
memory: 256M
|
||||
routes:
|
||||
- route: request-mirror-server.us-south.cf.appdomain.cloud
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"engines": {
|
||||
"node": "14.16.0"
|
||||
},
|
||||
"name": "reflector-server",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "node .",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "William Young (IBM)",
|
||||
"license": "UNLICENSED",
|
||||
"dependencies": {
|
||||
"body-parser": "^1.19.0",
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.17.1",
|
||||
"multer": "^1.4.2",
|
||||
"ws": "^7.4.6"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
// window.addEventListener('load', function () {
|
||||
console.log("Page loaded... connecting to server...");
|
||||
const webSocket = new WebSocket(`ws://${window.location.host}`);
|
||||
var last_contact = Date.now();
|
||||
setInterval( () => {
|
||||
if (last_contact + 5000 < Date.now()) {
|
||||
console.log("Connection to server hung...");
|
||||
}
|
||||
}, 3500 )
|
||||
webSocket.onopen = (e) => {
|
||||
webSocket.send("TEST");
|
||||
}
|
||||
webSocket.onclose = (e) => {
|
||||
console.log("Disconnected from server");
|
||||
}
|
||||
webSocket.onerror = (e) => {
|
||||
console.log("Connection ERROR");
|
||||
console.log(e);
|
||||
}
|
||||
webSocket.onmessage = (e) => {
|
||||
if( e.data === "PONG" ) { last_contact = Date.now(); return }
|
||||
if( e.data === "TEST" ) { return console.log("Connected to server"); }
|
||||
console.log(e.data);
|
||||
console.log(JSON.parse(e.data));
|
||||
}
|
||||
window.setInterval( ()=>webSocket.send('PING'), 1000 );
|
||||
// })
|
Loading…
Reference in New Issue