Note that this file will be modified at run time to store certificates and signing keys.
Start the proxy:
splicer config.json
Dynamic config reload:
kill -s HUP "$(pgrep -fn splicer)"
As a JavaScript module
See also example/index.js
import Splicer from 'splicer'// create a proxyconst proxy = new Splicer()proxy.on('tcpbind', port => { console.log(`started listening on ${port}`)})proxy.on('tcpunbind', port => { console.log(`stopped listening on ${port}`)})proxy.on('connection', socket => { console.log(`tcp connection on ${socket.localPort} from ${socket
License
MIT
.
remoteAddress
}`
)
})
proxy.on('request', (socket, name, app) => {
console.log(`[${new Date().toISOString()}] request for ${name} on ${socket.localPort} from ${socket.remoteAddress}`)
})
// map dns names to apps
proxy.names = {
'www.secure-http.localhost': 'secureHTTP',
'secure-http.localhost': 'secureHTTP',
'secure-tcp.localhost': 'secureTCP',
'insecure-http.localhost': {
appId: 'insecureHTTP'
}
}
// configure apps
proxy.apps = {
secureHTTP: {
tls: true,
http: {
cname: 'www.secure-tcp.localhost', // forces a redirect if host header does not match
auth: {
username: 'password' // http basic authentication
}
},
machines: {
main: true
},
ports: {
80: true, // mapping 80 to a specific destination port is unnecessary for apps that set the tls option
// but it should be explitly opened for answering acme http challenges and redirecting new visitors
443: 4430
}
},
secureTCP: {
tls: {
front: true,
back: false // tls option can be an object to indicate if backend connections should use tls
},
machines: {
main: true
},
ports: {
9000: 9001
}
},
insecureHTTP: {
http: {
pre: `return req => req.headers['x-added-for-upstream'] = 'foo'`, // these get eval'd
post: `return res => res.headers['x-added-for-client'] = 'bar'`,
rewriteHost: true // rewrite host header to match upstream machine:port (defaults to false)
},
machines: {
main: true
},
ports: {
80: 8000
}
}
}
// upstream ips
// note these are not stored directly on apps to make load balancing easier
proxy.machines = {
main: {
address: 'localhost'
}
}
// you can optionally override `balanceLoad`, by default it returns the first known machine