Skip to content

Commit

Permalink
feat: integrate Sentry; reroute all other paths to the website
Browse files Browse the repository at this point in the history
  • Loading branch information
arpitdalal committed Apr 22, 2024
1 parent 84f8374 commit 6643716
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 6 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SENTRY_DSN=YOUR_SENTRY_DSN
37 changes: 31 additions & 6 deletions index.js
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/",
Expand All @@ -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));
});
Expand All @@ -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) => {
Expand Down Expand Up @@ -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}`);
});
Expand Down
71 changes: 71 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "arpit.im",
"private": true,
"sideEffects": false,
"type": "module",
"scripts": {
"dev": "nodemon index.js",
"start": "node index.js"
Expand All @@ -12,6 +13,8 @@
"url": "https://arpitdalal.dev"
},
"dependencies": {
"@sentry/node": "^7.111.0",
"dotenv": "^16.4.5",
"express": "^4.19.2"
},
"devDependencies": {
Expand Down

0 comments on commit 6643716

Please sign in to comment.