Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs for non-html route encoding option #1434

Merged
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