Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@LuigiZaccagnini
Copy link
Contributor

fixes #195

  • Added changes to allow for headers to be written
  • I also updated the documents to show how to include headers to be written.

An example on how to write headers would be:

const http = require("http");
const express = require("express");
const terminus = require("../terminus/index.js");
const app = express();

app.get("/", (req, res) => {
  res.send("ok");
});

const server = http.createServer(app);

function healthCheck({ state }) {
  // `state.isShuttingDown` (boolean) shows whether the server is shutting down or not
  return Promise
    .resolve
    // optionally include a resolve value to be included as
    // info in the health check response
    ();
}

const options = {
  healthChecks: {
    "/healthcheck": healthCheck,
    verbatim: true,
    __unsafeExposeStackTraces: true,
  },
  headers: {
    "Access-Control-Allow-Origin": "*",
    "Access-Control-Allow-Methods": "OPTIONS, POST, GET",
  },
};

terminus.createTerminus(server, options);

server.listen(3000);

I tested it to enable CORS headers and everything seems to be working!

@ste2425
Copy link
Contributor

ste2425 commented Jan 13, 2022

Is there any movement on this? We've come up against a CORS issue that this functionality would allow us to solve. Would be great if this could get in.

@LuigiZaccagnini
Copy link
Contributor Author

@ste2425 Going to resolve the requested change today!

@LuigiZaccagnini
Copy link
Contributor Author

Hey @gergelyke-dd! I can't re-request a review so I just wanted to tag you to tell you I finished the changes!

@gergelyke
Copy link
Collaborator

Looks great! One question: with the introduction of res.writeHead, do we still need the res.status = … lines?

@gergelyke gergelyke changed the title Issue 195 custom header support Jan 14, 2022
@LuigiZaccagnini
Copy link
Contributor Author

@gergelyke good call! Just removed them and tested. Everything still works and the res.status is gone!

@gergelyke
Copy link
Collaborator

one last thing before we land it , would you mind adding some test coverage?

@LuigiZaccagnini
Copy link
Contributor Author

@gergelyke just added test coverage!

@gergelyke
Copy link
Collaborator

awesome, thank you πŸ‘

@gergelyke gergelyke merged commit 845734e into godaddy:main Jan 14, 2022
@github-actions
Copy link

πŸŽ‰ This PR is included in version 4.10.0 πŸŽ‰

The release is available on:

Your semantic-release bot πŸ“¦πŸš€

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Configurable health response options via middleware?

4 participants