Skip to content

Commit

Permalink
Add basic sentry error catching implementation with doppler secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
danielemery committed May 18, 2024
1 parent e07a6f5 commit de9c628
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ curl "https://keys.demery.net/api?allOf=demery&allOf=thunderbird&noneOf=disabled
### Running locally

```sh
deno run --allow-net --allow-env main.ts
doppler run -- deno run --allow-net --allow-env main.ts
```

### Run tests
Expand Down
1 change: 1 addition & 0 deletions deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export {
} from "https://deno.land/std@0.224.0/http/status.ts";
export { z } from "https://deno.land/x/zod@v3.23.8/mod.ts";
export { ZodError } from "https://deno.land/x/zod@v3.23.8/ZodError.ts";
export * as Sentry from "https://deno.land/x/sentry@7.116.0/index.mjs";
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
nativeBuildInputs = [ pkgs.bashInteractive ];
buildInputs = with pkgs; [
deno
doppler
];
};
});
Expand Down
8 changes: 8 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@ import start from "./src/server.ts";
import keys from "./src/public_keys.ts";
import { filterIncludesKey, parseParameters } from "./src/filter.ts";
import { parseEnvironmentVariables } from "./src/environment.ts";
import { Sentry } from "./deps.ts";

const environment = parseEnvironmentVariables(Deno.env.toObject());

if (environment.SENTRY_DSN) {
Sentry.init({
dsn: environment.SENTRY_DSN,
environment: environment.DOPPLER_ENVIRONMENT,
});
}

start(environment.PORT, {
filterIncludesKey,
parseParameters,
Expand Down
2 changes: 2 additions & 0 deletions src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { z } from "../deps.ts";

const environmentSchema = z.object({
PORT: z.string().regex(/^\d+$/).transform(Number).default("8000"),
DOPPLER_ENVIRONMENT: z.string(),
SENTRY_DSN: z.string().optional(),
});

export function parseEnvironmentVariables(variableObject: unknown) {
Expand Down

0 comments on commit de9c628

Please sign in to comment.