diff --git a/examples/non-html-pages/README.md b/examples/non-html-pages/README.md index 354f95be3..1236c7204 100644 --- a/examples/non-html-pages/README.md +++ b/examples/non-html-pages/README.md @@ -22,7 +22,7 @@ Inside of your Astro project, you'll see the following folders and files: ├── src/ │ └── pages/ │ └── index.astro -│ └── company.json.ts +│ └── about.json.ts └── package.json ``` diff --git a/examples/non-html-pages/src/pages/about.json.ts b/examples/non-html-pages/src/pages/about.json.ts new file mode 100644 index 000000000..af61847f3 --- /dev/null +++ b/examples/non-html-pages/src/pages/about.json.ts @@ -0,0 +1,11 @@ +// Returns the file body for this non-HTML file. +// The content type is based off of the extension in the filename, +// in this case: about.json. +export async function get() { + return { + body: JSON.stringify({ + name: 'Astro', + url: 'https://astro.build/', + }), + }; +} diff --git a/examples/non-html-pages/src/pages/company.json.ts b/examples/non-html-pages/src/pages/company.json.ts deleted file mode 100644 index c931c0e15..000000000 --- a/examples/non-html-pages/src/pages/company.json.ts +++ /dev/null @@ -1,8 +0,0 @@ -export async function get() { - return { - body: JSON.stringify({ - name: 'Astro', - url: 'https://astro.build/', - }), - }; -} diff --git a/examples/non-html-pages/src/pages/index.astro b/examples/non-html-pages/src/pages/index.astro index af1ed4326..accde929c 100644 --- a/examples/non-html-pages/src/pages/index.astro +++ b/examples/non-html-pages/src/pages/index.astro @@ -1,8 +1,4 @@ ---- -const url = `${Astro.request.canonicalURL.origin}/company.json`; -const response = await fetch(url); -const data = await response.json(); ---- + @@ -10,7 +6,13 @@ const data = await response.json(); Astro -

Astro

-
{JSON.stringify(data)}
+

Loading...

+