Skip to content

Commit f538f52

Browse files
committed
Set a file's contents which will override the response output
Issue mendhak#68
1 parent be4acc6 commit f538f52

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ app.use(function(req, res, next){
4747

4848
//Handle all paths
4949
app.all('*', (req, res) => {
50+
51+
if(process.env.OVERRIDE_RESPONSE_BODY_FILE_PATH){
52+
// Path is relative to current directory
53+
res.sendFile(process.env.OVERRIDE_RESPONSE_BODY_FILE_PATH, { root : __dirname});
54+
return;
55+
}
56+
5057
const echo = {
5158
path: req.path,
5259
headers: req.headers,

tests.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,23 @@ message " Stop containers "
532532
docker stop http-echo-tests
533533
sleep 5
534534

535+
message " Start container with a custom response body from a file "
536+
echo "<h1>Hello World</h1>" > test.html
537+
docker run -d --rm -v ${PWD}/test.html:/app/test.html --name http-echo-tests -p 8080:8080 -e OVERRIDE_RESPONSE_BODY_FILE_PATH=/test.html -t mendhak/http-https-echo:testing
538+
sleep 5
539+
RESPONSE_BODY=$(curl -s http://localhost:8080)
540+
if [[ "$RESPONSE_BODY" == "<h1>Hello World</h1>" ]]
541+
then
542+
passed "Custom response body from file"
543+
else
544+
failed "Custom response body from file failed"
545+
exit 1
546+
fi
547+
548+
message " Stop containers "
549+
docker stop http-echo-tests
550+
sleep 5
551+
535552
popd
536553
rm -rf testarea
537554
message "DONE"

0 commit comments

Comments
 (0)