Skip to content

Commit

Permalink
Add docs for non-html route encoding option (#1434)
Browse files Browse the repository at this point in the history
* Add docs for non-html route encoding option

* Apply suggestions from code review

Co-authored-by: Sarah Rainsberger <[email protected]>

Co-authored-by: Sarah Rainsberger <[email protected]>
  • Loading branch information
altano and sarah11918 authored Sep 9, 2022
1 parent a5fd0f9 commit 35a8e4a
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/pages/en/core-concepts/astro-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,21 @@ export const get: APIRoute = ({ params, request }) => {
};
```

You can optionally return an `encoding` option in static builds. It can be any valid [`BufferEncoding`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/bdd02508ddb5eebcf701fdb8ffd6e84eabf47885/types/node/buffer.d.ts#L169) accepted by node.js' `fs.writeFile` method. For example, to produce a binary png image using SSG:

```ts title="src/pages/image.png.ts" {7}
import type { APIRoute } from 'astro';

export const get: APIRoute = ({ params, request }) => {
const buffer = ...;
return {
body: buffer.toString('binary'),
encoding: 'binary',
};
};

```

## Custom 404 Error Page

For a custom 404 error page, you can create a `404.astro` or `404.md` file in `/src/pages`.
Expand Down

0 comments on commit 35a8e4a

Please sign in to comment.