-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove endpoint handling infra (#9775)
* remove endpoint handling infra * add changeset
- Loading branch information
Showing
8 changed files
with
31 additions
and
91 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,5 @@ | ||
--- | ||
"astro": patch | ||
--- | ||
|
||
Simplifies internals that handle endpoints. |
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
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,28 +1,3 @@ | ||
import { Pipeline } from '../pipeline.js'; | ||
import type { Environment } from '../render/index.js'; | ||
|
||
/** | ||
* Thrown when an endpoint contains a response with the header "X-Astro-Response" === 'Not-Found' | ||
*/ | ||
export class EndpointNotFoundError extends Error { | ||
originalResponse: Response; | ||
constructor(originalResponse: Response) { | ||
super(); | ||
this.originalResponse = originalResponse; | ||
} | ||
} | ||
|
||
export class SSRRoutePipeline extends Pipeline { | ||
constructor(env: Environment) { | ||
super(env); | ||
this.setEndpointHandler(this.#ssrEndpointHandler); | ||
} | ||
|
||
// This function is responsible for handling the result coming from an endpoint. | ||
async #ssrEndpointHandler(request: Request, response: Response): Promise<Response> { | ||
if (response.headers.get('X-Astro-Response') === 'Not-Found') { | ||
throw new EndpointNotFoundError(response); | ||
} | ||
return response; | ||
} | ||
} | ||
export class SSRRoutePipeline extends Pipeline {} |
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
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
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
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
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