DEV Community

Cover image for Working on GoDaddy Terminus
Luigi Zaccagnini
Luigi Zaccagnini

Posted on

Working on GoDaddy Terminus

Hello! Welcome to another blog post. Today I will be discussing my progress on my Telescope issue and how I got to Terminus.

Trying to Solve the Problem

To start, I thought I could solve Telescopes Issue by fixing some code on Telescope or Satellite in order for the CORS errors to stop. I soon learned that the main problem wasn't fixable from our code bases and had to be fixed from Terminus.

Working on Terminus

Once I moved to Terminus's issue I began to start learning the code and ways I can solve the CORS issue. I discussed ways inside the issue thread about how I can solve the CORS issue and how I could add middleware. The proposed ideas were all hypothetical solutions so I didn't know if they could work until I started working in the code.

Problems Encountered

While trying to solve this problem I tried to add middleware with compose-middleware. While trying to implement it I had troubles with integrating the middleware with the server. Since the middleware wasn't working I attempted to allow users to write headers instead.

Coding in the Terminus Project

Once I got comfortable and understood the code of the project I wanted to create a mock project to help.

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);
Enter fullscreen mode Exit fullscreen mode

This test project would help me test if I could pass headers to my local version of Terminus, and if I could fix any CORS related issues with the health check.

Within Terminus I wrote an extra parameter to allow users to send over their header options:

 decorateWithSignalHandler(server, state, {
    signals,
    onSignal,
    beforeShutdown,
    onShutdown,
    timeout,
    logger
  }, options.headers)
Enter fullscreen mode Exit fullscreen mode

By passing the header parameter through the decorateWithSignalHandler I am now able to give the sendSuccess and sendFailure functions the headers information needed so I could write my CORS headers.

Conclusion

So far everything is working and the next steps are to get the pull request accepted and to figure out a way to include middleware into the project.

Top comments (0)