@@ -23,7 +23,7 @@ module.exports = class ViewerRequestInterface {
2323 createReq ( ) {
2424 const req = {
2525 method : this . cloudFrontRequest . method ,
26- originalUrl : this . cloudFrontRequest . uri ,
26+ originalUrl : this . originalUrl ,
2727 url : this . originalUrl ,
2828 headers : {
2929 host : util . getHeader ( this . cloudFrontRequest , "host" ) ,
@@ -42,27 +42,41 @@ module.exports = class ViewerRequestInterface {
4242 setHeader : ( key , val ) => {
4343 this . headers [ key ] = val ;
4444 } ,
45- end : body => {
46- // since the user-agent header will be overwritten with CloudFront
47- // we use this to hint at the real one, but:
48- // 1. it will not affect the cache-key
49- // 2. prerender.cloud will only see it once (after that, the req will be cached in CloudFront)
50- // 3. we don't need this for anything other than the potential for user stats/analytics in prerender.cloud
51- // (i.e. the user can see the user-agent of the request that triggered the first CloudFront request)
52- this . cloudFrontRequest . headers [ util . USER_AGENT_PLACEHOLDER ] = [
53- {
54- key : util . USER_AGENT_PLACEHOLDER ,
55- value : util . getHeader ( this . cloudFrontRequest , "user-agent" )
56- }
57- ] ;
45+ writeHead ( _status , _headers ) { }
46+ } ;
5847
59- this . cloudFrontRequest . uri = util . createUri ( this . originalUrl , true ) ;
48+ res . end = body => {
49+ // since the user-agent header will be overwritten with CloudFront
50+ // we use this to hint at the real one, but:
51+ // 1. it will not affect the cache-key
52+ // 2. prerender.cloud will only see it once (after that, the req will be cached in CloudFront)
53+ // 3. we don't need this for anything other than the potential for user stats/analytics in prerender.cloud
54+ // (i.e. the user can see the user-agent of the request that triggered the first CloudFront request)
55+ this . cloudFrontRequest . headers [ util . USER_AGENT_PLACEHOLDER ] = [
56+ {
57+ key : util . USER_AGENT_PLACEHOLDER ,
58+ value : util . getHeader ( this . cloudFrontRequest , "user-agent" )
59+ }
60+ ] ;
6061
61- console . log ( { shouldPrerender : true , uri : this . originalUrl } ) ;
62+ const origCloudFrontUri = this . cloudFrontRequest . uri ;
6263
63- this . callback ( null , this . cloudFrontRequest ) ;
64- } ,
65- writeHead ( _status , _headers ) { }
64+ // res.prerender.url.requestedPath is set by https://github.com/sanfrancesco/prerendercloud-nodejs
65+ // specifically for this Lambda lib - it's the requested path after applying the whitelistQueryParams
66+ this . cloudFrontRequest . uri = util . createUri (
67+ res . prerender . url . requestedPath ,
68+ true
69+ ) ;
70+
71+ console . log ( {
72+ shouldPrerender : true ,
73+ cloudFrontUriAfterEncode : this . cloudFrontRequest . uri ,
74+ requestedUriAfterWhitelist : res . prerender . url . requestedPath ,
75+ originalCloudFrontUri : origCloudFrontUri ,
76+ originalCloudFrontQuerystring : this . cloudFrontRequest . querystring
77+ } ) ;
78+
79+ this . callback ( null , this . cloudFrontRequest ) ;
6680 } ;
6781
6882 res . headers = { } ;
0 commit comments