-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: integrate Sentry; reroute all other paths to the website
- Loading branch information
1 parent
84f8374
commit 6643716
Showing
4 changed files
with
106 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SENTRY_DSN=YOUR_SENTRY_DSN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,34 @@ | ||
const express = require("express"); | ||
import "dotenv/config"; | ||
import express from "express"; | ||
import * as Sentry from "@sentry/node"; | ||
|
||
if (!process.env.SENTRY_DSN) { | ||
throw new Error("SENTRY_DSN is not defined in the environment variables."); | ||
} | ||
const MODE = process.env.NODE_ENV; | ||
|
||
const app = express(); | ||
const port = 3000; | ||
|
||
Sentry.init({ | ||
dsn: process.env.SENTRY_DSN, | ||
environment: MODE, | ||
tracesSampleRate: MODE === "production" ? 1 : 0, | ||
denyUrls: [/\/healthcheck/], | ||
beforeSend(event) { | ||
// ignore all healthcheck related transactions | ||
// note that name of header here is case-sensitive | ||
if (event.request?.headers?.["x-healthcheck"] === "true") { | ||
return null; | ||
} | ||
|
||
return event; | ||
}, | ||
}); | ||
|
||
app.use(Sentry.Handlers.requestHandler()); | ||
app.use(Sentry.Handlers.tracingHandler()); | ||
|
||
const URLS = { | ||
website: "https://arpitdalal.dev/", | ||
blog: "https://blog.arpitdalal.dev/", | ||
|
@@ -12,10 +38,6 @@ const URLS = { | |
mail: "mailto:[email protected]", | ||
}; | ||
|
||
app.get("/", (req, res) => { | ||
res.redirect(prepareUrlWithQueryParams(req, URLS.website)); | ||
}); | ||
|
||
app.get("/b/:path(*)?", (req, res) => { | ||
res.redirect(prepareUrlWithPathAndQueryParams(req, URLS.blog)); | ||
}); | ||
|
@@ -24,7 +46,6 @@ app.get("/blog/:path(*)?", (req, res) => { | |
}); | ||
|
||
app.get("/gh/:path(*)?", (req, res) => { | ||
console.log(prepareUrlWithPathAndQueryParams(req, URLS.github)); | ||
res.redirect(prepareUrlWithPathAndQueryParams(req, URLS.github)); | ||
}); | ||
app.get("/github/:path(*)?", (req, res) => { | ||
|
@@ -53,6 +74,10 @@ app.get("/healthcheck", (_, res) => { | |
res.send("OK"); | ||
}); | ||
|
||
app.get("/:path(*)?", (req, res) => { | ||
res.redirect(prepareUrlWithPathAndQueryParams(req, URLS.website)); | ||
}); | ||
|
||
app.listen(port, () => { | ||
console.log(`Server is running on port ${port}`); | ||
}); | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters