-
Notifications
You must be signed in to change notification settings - Fork 8
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #318 +/- ##
======================================
Coverage ? 80.05%
======================================
Files ? 49
Lines ? 2226
Branches ? 569
======================================
Hits ? 1782
Misses ? 444
Partials ? 0
Continue to review full report at Codecov.
|
* Don't run lint and test compile. * Read key and cert from cwd. * Add script for preparing certs. * Move the script. * Fix the script. * Add API. * Add helmet. * Update script. * Re-introduce long post-install.
This reverts commit 2e051fb.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm; I had some really minor suggestions that are totally unrelated to the way things work.
Good job 👍 👍
@@ -94,6 +95,7 @@ | |||
"unmock-fetch": "file:packages/unmock-fetch", | |||
"unmock-jest": "file:packages/unmock-jest", | |||
"unmock-node": "file:packages/unmock-node", | |||
"unmock-server": "file:packages/unmock-server", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this also be included in the lint-ts
and lint-ts-fix
scripts above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
packages/unmock-server/src/proxy.ts
Outdated
}); | ||
|
||
proxySocket.on("error", () => { | ||
socket.write("HTTP/" + req.httpVersion + " 500 Connection error\r\n\r\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could create a function to maintain the HTTP/${req.httpVersion} ${msg}\r\n\r\n
pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
}); | ||
|
||
socket.on("data", chunk => { | ||
proxySocket.write(chunk); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need any checks on the chunk being written (e.g. that it ends with \r\n\r\n
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we need that, it's up to the target server to return proper data. Also not sure how that would work with encryption.
packages/unmock-server/src/server.ts
Outdated
import { createUnmockAlgo } from "./unmock"; | ||
|
||
const httpPort = 8000; | ||
const httpsPort = 8443; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is linked to the port defined in proxy.ts
; could benefit from a shared definition to avoid potential breakage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added constants.ts
.
packages/unmock-server/src/server.ts
Outdated
export const startServer = (app: express.Express) => { | ||
const options = { | ||
key: fs.readFileSync(`${process.cwd()}/key.pem`), | ||
cert: fs.readFileSync(`${process.cwd()}/cert.pem`), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say a .env
file could be more useful here than cwd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably, will do later on if we work on this more.
Changes
unmock-server
packageproxy.ts
) and unmock server (server.ts
)X-Forwarded-Host
(orHost
) header to determine where the request was going and serializes the request to aISerializedRequest
ISerializedRequest
is handled withunmock
Instructions
key.pem
andcert.pem
) for a given domain:__unmock__
folder with service forpetstore.swagger.io/v2
npm run compile && node packages/unmock-server/index.js
. This starts the proxy atlocalhost:8008
and Unmock server atlocalhost:8000
(HTTP) andlocalhost:8443
(HTTPS)http_proxy=http://localhost:8008 HTTPS_PROXY=http://localhost:8008 SSL_CERT_FILE=cert.pem curl -i http://petstore.swagger.io/v2/pet/23
Issues
Certificates in case of HTTPS
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
)Setting the proxy
http_proxy
andhttps_proxy
(or uppercased) environment variables, so if application is using those, requests are easy to proxy to the running Unmock proxyunmock
library)Managing service state
/api
for setting state