Skip to content

Commit

Permalink
docs: updated proxy docs - renamed already used const proxy to proxyS…
Browse files Browse the repository at this point in the history
…erver
  • Loading branch information
dancastillo committed Jul 17, 2022
1 parent b6af4e6 commit 531f14a
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions docs/best-practices/proxy.md
Expand Up @@ -20,10 +20,10 @@ import { createServer } from 'http'
import proxy from 'proxy'

const server = await buildServer()
const proxy = await buildProxy()
const proxyServer = await buildProxy()

const serverUrl = `http://localhost:${server.address().port}`
const proxyUrl = `http://localhost:${proxy.address().port}`
const proxyUrl = `http://localhost:${proxyServer.address().port}`

server.on('request', (req, res) => {
console.log(req.url) // '/hello?foo=bar'
Expand All @@ -47,7 +47,7 @@ console.log(response.statusCode) // 200
console.log(JSON.parse(data)) // { hello: 'world' }

server.close()
proxy.close()
proxyServer.close()
client.close()

function buildServer () {
Expand All @@ -73,12 +73,12 @@ import { createServer } from 'http'
import proxy from 'proxy'

const server = await buildServer()
const proxy = await buildProxy()
const proxyServer = await buildProxy()

const serverUrl = `http://localhost:${server.address().port}`
const proxyUrl = `http://localhost:${proxy.address().port}`
const proxyUrl = `http://localhost:${proxyServer.address().port}`

proxy.authenticate = function (req, fn) {
proxyServer.authenticate = function (req, fn) {
fn(null, req.headers['proxy-authorization'] === `Basic ${Buffer.from('user:pass').toString('base64')}`)
}

Expand Down Expand Up @@ -107,7 +107,7 @@ console.log(response.statusCode) // 200
console.log(JSON.parse(data)) // { hello: 'world' }

server.close()
proxy.close()
proxyServer.close()
client.close()

function buildServer () {
Expand All @@ -124,3 +124,4 @@ function buildProxy () {
})
}
```

0 comments on commit 531f14a

Please sign in to comment.