Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ jobs:
steps:
- uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
with:
egress-policy: audit
# allowed-endpoints: >
# sparrow.cloudflare.com:443
# api.cloudflare.com:443
# api.github.com:443
# github.com:443
# hooks.slack.com:443
# registry.npmjs.org:443
egress-policy: block
allowed-endpoints: >
sparrow.cloudflare.com:443
api.cloudflare.com:443
api.github.com:443
github.com:443
hooks.slack.com:443
registry.npmjs.org:443
sentry.io:443

- name: Git Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
Expand Down
10 changes: 10 additions & 0 deletions src/middleware/throwMiddleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { Middleware } from './middleware';

/**
* Middleware that exists just to throw an error
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

35ffba21606a3a7ba25a3612ea624aec

*/
export class ThrowMiddleware implements Middleware {
handle(): Promise<Response> {
throw new Error('Throw endpoint hit');
}
}
3 changes: 3 additions & 0 deletions src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { OriginMiddleware } from '../middleware/originMiddleware';
import { R2Middleware } from '../middleware/r2Middleware';
import { RedirectionMiddleware } from '../middleware/redirectionMiddleware';
import { SubtitutionMiddleware } from '../middleware/subtituteMiddleware';
import { ThrowMiddleware } from '../middleware/throwMiddleware';
import type { Router } from './router';

export function registerRoutes(router: Router): void {
Expand Down Expand Up @@ -63,6 +64,8 @@ export function registerRoutes(router: Router): void {
originMiddleware,
]);

router.post('/_throw', [new ThrowMiddleware()]);

router.get('*', [new NotFoundMiddleware()]);

router.all('*', [new MethodNotAllowedMiddleware()]);
Expand Down
8 changes: 8 additions & 0 deletions src/routes/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ export class Router {
return callMiddlewareChain(middlewareChain, req, ctx, unsubstitutedUrl);
});
}

post(endpoint: string, middlewares: Middleware[]): void {
const middlewareChain = buildMiddlewareChain(middlewares);

this.itty.post(endpoint, (req, ctx, unsubstitutedUrl) => {
return callMiddlewareChain(middlewareChain, req, ctx, unsubstitutedUrl);
});
}
}

type MiddlewareChain = (
Expand Down
7 changes: 0 additions & 7 deletions src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ export default {
execution: ctx,
};

if (
env.ENVIRONMENT === 'staging' &&
request.url === '/_657ee98d-f9d3-46cd-837b-f58a88add70a'
) {
throw new Error('sentry source map testing');
}

return await router.handle(request, context);
} catch (e) {
// Send to sentry, if it's disabled this will just noop
Expand Down