Skip to content

Commit

Permalink
Set a file's contents which will override the response output
Browse files Browse the repository at this point in the history
  • Loading branch information
mendhak committed Aug 11, 2024
1 parent be4acc6 commit 77b2e58
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ app.use(function(req, res, next){

//Handle all paths
app.all('*', (req, res) => {

if(process.env.OVERRIDE_RESPONSE_BODY_FILE_PATH){
// Path is relative to current directory
res.sendFile(process.env.OVERRIDE_RESPONSE_BODY_FILE_PATH, { root : __dirname});
return;
}

const echo = {
path: req.path,
headers: req.headers,
Expand Down
17 changes: 17 additions & 0 deletions tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,23 @@ message " Stop containers "
docker stop http-echo-tests
sleep 5

message " Start container with a custom response body from a file "
echo "<h1>Hello World</h1>" > test.html
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
sleep 5
RESPONSE_BODY=$(curl -s http://localhost:8080)
if [[ "$RESPONSE_BODY" == "<h1>Hello World</h1>" ]]
then
passed "Custom response body from file"
else
failed "Custom response body from file failed"
exit 1
fi

message " Stop containers "
docker stop http-echo-tests
sleep 5

popd
rm -rf testarea
message "DONE"

0 comments on commit 77b2e58

Please sign in to comment.