-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements redirects, headers for SSR (#2798)
* Implements redirects, headers for SSR * Move away from an explicit Request * Properly handle endpoint routes in the build * chore(lint): ESLint fix * Update based on review comments Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
8f13b3d
commit 4c25a1c
Showing
33 changed files
with
697 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Implement APIs for headers for SSR flag |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import lightcookie from 'lightcookie'; | ||
|
||
|
||
export function isLoggedIn(request: Request): boolean { | ||
const cookie = request.headers.get('cookie'); | ||
const parsed = lightcookie.parse(cookie); | ||
return 'user-id' in parsed; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
import Header from '../components/Header.astro'; | ||
import Container from '../components/Container.astro'; | ||
import { getCart } from '../api'; | ||
import { isLoggedIn } from '../models/user'; | ||
if(!isLoggedIn(Astro.request)) { | ||
return Astro.redirect('/'); | ||
} | ||
// They must be logged in. | ||
const user = { name: 'test'}; // getUser? | ||
const cart = await getCart(); | ||
--- | ||
<html> | ||
<head> | ||
<title>Cart | Online Store</title> | ||
<style> | ||
h1 { | ||
font-size: 36px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<Header /> | ||
|
||
<Container tag="main"> | ||
<h1>Cart</h1> | ||
<p>Hi { user.name }! Here are your cart items:</p> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Item</th> | ||
<th>Count</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{cart.items.map(item => <tr> | ||
<td>{item.name}</td> | ||
<td>{item.count}</td> | ||
</tr>)} | ||
</tbody> | ||
</table> | ||
</Container> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
import Header from '../components/Header.astro'; | ||
import Container from '../components/Container.astro'; | ||
--- | ||
<html> | ||
<head> | ||
<title>Online Store</title> | ||
<style> | ||
h1 { | ||
font-size: 36px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<Header /> | ||
|
||
<Container tag="main"> | ||
<h1>Login</h1> | ||
<form action="/login.form" method="POST"> | ||
<label for="name">Name</label> | ||
<input type="text" name="name"> | ||
|
||
<label for="password">Password</label> | ||
<input type="password" name="password"> | ||
|
||
<input type="submit" value="Submit"> | ||
</form> | ||
</Container> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
export function post(params, request) { | ||
return new Response(null, { | ||
status: 301, | ||
headers: { | ||
'Location': '/', | ||
'Set-Cookie': 'user-id=1; Path=/; Max-Age=2592000' | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["ES2015", "DOM"], | ||
"module": "ES2022", | ||
"moduleResolution": "node", | ||
"types": ["astro/env"] | ||
} | ||
} |
Oops, something went wrong.