From 5370bba0b09d7337927b6685029e48d05b1500bd Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Fri, 25 Feb 2022 08:28:38 -0800 Subject: [PATCH] get new example working during build --- examples/non-html-pages/README.md | 2 +- examples/non-html-pages/src/pages/about.json.ts | 11 +++++++++++ .../non-html-pages/src/pages/company.json.ts | 8 -------- examples/non-html-pages/src/pages/index.astro | 16 +++++++++------- 4 files changed, 21 insertions(+), 16 deletions(-) create mode 100644 examples/non-html-pages/src/pages/about.json.ts delete mode 100644 examples/non-html-pages/src/pages/company.json.ts 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...

+