forked from netlify/edge-functions-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (27 loc) · 1014 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import repoLink from "../../components/repo-link.js";
export default {
title: "Rewrite with Edge Functions",
metaDescription: "Rewrite HTTP requests with an edge function",
page: function() {
return `
<section>
<h1>Rewrite with Edge Functions</h1>
<p>You can rewrite requests on one URL to resources available on another URL using an Edge Function.</p>
<pre><code>import type { Context } from "https://edge.netlify.com";
export default async (request: Request, context: Context) => {
return context.rewrite("/something-to-serve-with-a-rewrite");
};
</code></pre>
<h2>See this in action</h2>
<ul>
<li><a href="/rewrite">Run the rewrite edge function</a></li>
<li>${repoLink("rewrite.ts")}</li>
</ul>
<div class="protip">
<h2>Pro tip!</h2>
<p>You can combine <a href="/example/localized-content">geolocation data</a> with URL rewrites to serve different URLs powering internationalized content.</p>
</div>
</section>
`;
},
};