File tree Expand file tree Collapse file tree 4 files changed +52
-16
lines changed
edge-site/netlify/functions
react-router-edge-site/netlify/functions
react-router-serverless-site/netlify/functions
serverless-site/netlify/functions Expand file tree Collapse file tree 4 files changed +52
-16
lines changed Original file line number Diff line number Diff line change 1- import { type Config , purgeCache } from "@netlify/functions" ;
1+ import { type Config , type Context , purgeCache } from "@netlify/functions" ;
22
3- const handler = async ( request : Request ) : Promise < Response > => {
3+ const handler = async (
4+ request : Request ,
5+ context : Context ,
6+ ) : Promise < Response > => {
47 const url = new URL ( request . url ) ;
58 const tagToPurge = url . searchParams . get ( "tag" ) ;
69
@@ -14,8 +17,17 @@ const handler = async (request: Request): Promise<Response> => {
1417 ) ;
1518 }
1619
17- console . log ( "Purging" , tagToPurge ) ;
18- await purgeCache ( { tags : [ tagToPurge ] } ) ;
20+ // e2e tests exclusively create manual deploys, so this assumption is safe
21+ if ( ! context . url . hostname . includes ( "--" ) ) {
22+ return Response . json (
23+ { error : "No deploy alias found in hostname (missing --)" } ,
24+ { status : 400 } ,
25+ ) ;
26+ }
27+ await purgeCache ( {
28+ tags : [ tagToPurge ] ,
29+ deployAlias : context . url . hostname . split ( "--" ) [ 0 ] ,
30+ } ) ;
1931
2032 return new Response ( null , { status : 204 } ) ;
2133} ;
Original file line number Diff line number Diff line change 1- import { type Config , purgeCache } from '@netlify/functions'
1+ import { type Config , type Context , purgeCache } from '@netlify/functions'
22
3- const handler = async ( request : Request ) : Promise < Response > => {
3+ const handler = async ( request : Request , context : Context ) : Promise < Response > => {
44 const url = new URL ( request . url )
55 const tagToPurge = url . searchParams . get ( 'tag' )
66
@@ -14,8 +14,14 @@ const handler = async (request: Request): Promise<Response> => {
1414 )
1515 }
1616
17- console . log ( 'Purging' , tagToPurge )
18- await purgeCache ( { tags : [ tagToPurge ] } )
17+ // e2e tests exclusively create manual deploys, so this assumption is safe
18+ if ( ! context . url . hostname . includes ( '--' ) ) {
19+ return Response . json ( { error : 'No deploy alias found in hostname (missing --)' } , { status : 400 } )
20+ }
21+ await purgeCache ( {
22+ tags : [ tagToPurge ] ,
23+ deployAlias : context . url . hostname . split ( '--' ) [ 0 ] ,
24+ } )
1925
2026 return new Response ( null , { status : 204 } )
2127}
Original file line number Diff line number Diff line change 1- import { type Config , purgeCache } from '@netlify/functions'
1+ import { type Config , type Context , purgeCache } from '@netlify/functions'
22
3- const handler = async ( request : Request ) : Promise < Response > => {
3+ const handler = async ( request : Request , context : Context ) : Promise < Response > => {
44 const url = new URL ( request . url )
55 const tagToPurge = url . searchParams . get ( 'tag' )
66
@@ -14,8 +14,14 @@ const handler = async (request: Request): Promise<Response> => {
1414 )
1515 }
1616
17- console . log ( 'Purging' , tagToPurge )
18- await purgeCache ( { tags : [ tagToPurge ] } )
17+ // e2e tests exclusively create manual deploys, so this assumption is safe
18+ if ( ! context . url . hostname . includes ( '--' ) ) {
19+ return Response . json ( { error : 'No deploy alias found in hostname (missing --)' } , { status : 400 } )
20+ }
21+ await purgeCache ( {
22+ tags : [ tagToPurge ] ,
23+ deployAlias : context . url . hostname . split ( '--' ) [ 0 ] ,
24+ } )
1925
2026 return new Response ( null , { status : 204 } )
2127}
Original file line number Diff line number Diff line change 1- import { type Config , purgeCache } from "@netlify/functions" ;
1+ import { type Config , type Context , purgeCache } from "@netlify/functions" ;
22
3- const handler = async ( request : Request ) : Promise < Response > => {
3+ const handler = async (
4+ request : Request ,
5+ context : Context ,
6+ ) : Promise < Response > => {
47 const url = new URL ( request . url ) ;
58 const tagToPurge = url . searchParams . get ( "tag" ) ;
69
@@ -14,8 +17,17 @@ const handler = async (request: Request): Promise<Response> => {
1417 ) ;
1518 }
1619
17- console . log ( "Purging" , tagToPurge ) ;
18- await purgeCache ( { tags : [ tagToPurge ] } ) ;
20+ // e2e tests exclusively create manual deploys, so this assumption is safe
21+ if ( ! context . url . hostname . includes ( "--" ) ) {
22+ return Response . json (
23+ { error : "No deploy alias found in hostname (missing --)" } ,
24+ { status : 400 } ,
25+ ) ;
26+ }
27+ await purgeCache ( {
28+ tags : [ tagToPurge ] ,
29+ deployAlias : context . url . hostname . split ( "--" ) [ 0 ] ,
30+ } ) ;
1931
2032 return new Response ( null , { status : 204 } ) ;
2133} ;
You can’t perform that action at this time.
0 commit comments