Skip to content
This repository has been archived by the owner on Nov 4, 2023. It is now read-only.

Commit

Permalink
Update proxyToGce
Browse files Browse the repository at this point in the history
  • Loading branch information
Maigret Aurélien committed May 9, 2020
1 parent fa6464e commit 3ba5f7a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 36 deletions.
36 changes: 0 additions & 36 deletions proxy-to-gce.js

This file was deleted.

38 changes: 38 additions & 0 deletions proxy-to-gce/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const net = require('net')
const http = require('http')

module.exports = function ({ gceSecurePort = 6731, managerPort = 6732, proxyPort = 443, managerStopPath = 'stop-proxy-to-gce' }) {
const proxy = net.createServer(function (client) {
client.once('data', function (buf) {
const proxy = net.createConnection(gceSecurePort, function () {
proxy.write(buf)
client.pipe(proxy).pipe(client)
})
proxy.on('error', () => {})
})
client.on('error', () => {})
})

const manager = http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' })
res.end('github.com/Dewep/GCE:proxy-to-gce', function () {
if (req.url === '/' + managerStopPath) {
shutdown()
}
})
})

function shutdown () {
proxy.close(function () {
manager.close(function () {
process.exit(0)
})
})
}

proxy.on('error', shutdown)
manager.on('error', shutdown)

proxy.listen(proxyPort)
manager.listen(managerPort)
}

0 comments on commit 3ba5f7a

Please sign in to comment.