Skip to content

Commit

Permalink
Merge pull request #91 from Carifio24/health-check
Browse files Browse the repository at this point in the history
Allow requests to `/` and modify message
  • Loading branch information
Carifio24 authored Oct 10, 2023
2 parents f5a1e26 + 5e63c96 commit 33fb0f4
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ const store = new SequelizeStore({

async function apiKeyMiddleware(req: Request, res: ExpressResponse, next: NextFunction): Promise<void> {

if (req.originalUrl === "/") {
next();
return;
}

// The whitelisting of hosts is temporary!
const host = req.headers.origin;
const validOrigin = host && ALLOWED_ORIGINS.includes(host);
Expand Down Expand Up @@ -172,8 +177,15 @@ app.all("*", (req, _res, next) => {
});

// simple route
app.get("/", (_req, res) => {
res.json({ message: "Welcome to the CosmicDS server." });
app.get("/", async (req, res) => {
const key = req.get("Authorization");
const apiKey = key ? await getAPIKey(key) : null;
const apiKeyExists = apiKey !== null;
let message = "Welcome to the CosmicDS server!";
if (!apiKeyExists) {
message += " You'll need to include a valid API key with your requests in order to access other endpoints.";
}
res.json({ message: message });
});

function _sendUserIdCookie(userId: number, res: ExpressResponse): void {
Expand Down

0 comments on commit 33fb0f4

Please sign in to comment.