From 35a8e4a6b3e8cfe0fb4a170eb6677f0da7c893a7 Mon Sep 17 00:00:00 2001 From: Alan Date: Fri, 9 Sep 2022 15:41:14 -0700 Subject: [PATCH] Add docs for non-html route encoding option (#1434) * Add docs for non-html route encoding option * Apply suggestions from code review Co-authored-by: Sarah Rainsberger Co-authored-by: Sarah Rainsberger --- src/pages/en/core-concepts/astro-pages.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/pages/en/core-concepts/astro-pages.md b/src/pages/en/core-concepts/astro-pages.md index 639cd6a4b7d7d..ac69da4e2756f 100644 --- a/src/pages/en/core-concepts/astro-pages.md +++ b/src/pages/en/core-concepts/astro-pages.md @@ -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`.