Skip to content

Commit

Permalink
Update features description (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexnguyennz authored Dec 19, 2023
1 parent f719462 commit 22731af
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/silver-boxes-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro-aws-amplify": patch
---

Update features description (middleware)
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,10 @@ For base path routes, create a rewrite of:
- server and hybrid mode
- image optimization with `<Image>` and `<Picture />` (tentative)
- base paths
- middleware

### Unsupported / Untested

- pre-rendered pages (without workaround above)
- remote images
- middleware
- ???

## Monorepo Project Setup
Expand Down
3 changes: 3 additions & 0 deletions demos/blog/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import awsAmplify from "astro-aws-amplify";
export default defineConfig({
site: "https://example.com",
trailingSlash: "always",
image: {
domains: ["picsum.photos"],
},
integrations: [mdx(), sitemap()],
output: "server",
adapter: awsAmplify(),
Expand Down
11 changes: 11 additions & 0 deletions demos/blog/src/middleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @type {import("astro").MiddlewareResponseHandler}
*/
export function onRequest({ locals, request }, next) {
// intercept data from a request
// optionally, modify the properties in `locals`
locals.title = "Title set by middleware";

// return a Response or the result of calling `next()`
return next();
}
15 changes: 15 additions & 0 deletions demos/blog/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
import { Image } from "astro:assets";
import BaseHead from "../components/BaseHead.astro";
import Header from "../components/Header.astro";
import Footer from "../components/Footer.astro";
Expand All @@ -8,6 +10,10 @@ const response = await fetch(
"https://uselessfacts.jsph.pl/api/v2/facts/random",
);
const data = await response.json();
const locals = Astro.locals;
console.log("data", locals);
---

<!doctype html>
Expand All @@ -22,6 +28,15 @@ const data = await response.json();

<h2>Random fact: {data.text}</h2>

<h3>{locals.title}</h3>

<Image
src="https://picsum.photos/200/300"
width="200"
height="200"
alt=""
/>

<p>
Welcome to the official <a href="https://astro.build/">Astro</a> blog
starter template. This template serves as a lightweight,
Expand Down
4 changes: 1 addition & 3 deletions packages/adapter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,10 @@ For base path routes, create a rewrite of:
- server and hybrid mode
- image optimization with `<Image>` and `<Picture />` (tentative)
- base paths
- middleware

### Unsupported / Untested

- pre-rendered pages (without workaround above)
- remote images
- middleware
- ???

## Monorepo Project Setup
Expand Down

0 comments on commit 22731af

Please sign in to comment.