Skip to content

Instantly share code, notes, and snippets.

@williamli
Last active May 21, 2019 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save williamli/c8c90d4e62abe609dfe9fe495568b8c9 to your computer and use it in GitHub Desktop.
Save williamli/c8c90d4e62abe609dfe9fe495568b8c9 to your computer and use it in GitHub Desktop.
A summary of https://github.com/zeit/now-proxy/issues/1136 (private issue)

Summary

When using now.json's route to perform server side redirects, like the following 3 different cases:

  1. hardcoded path, there is a Lambda function called "thoughts"
{ "src": "/thoughts/", "dest": "/blogIndex" },
{ "src": "/thoughts", "status": 301, "headers": { "Location": "/thoughts/" } },
  1. using parameter as path
{ 
  "src": "/(?<page>[^/]*)/", 
  "dest": "/?page=$page"
},
{ 
  "src": "/(?<page>[^/]*)", 
  "status": 301,
  "headers": { "Location": "/$page/" }
}
  1. hardcoding the redirect location
{
  "src": "/(?<locale>[^/]*)", 
  "status": 301,
  "headers": { "Location": "https://ibcol-dev.bbi.now.sh/en-gb/how/" }
}

If the original req url path clashes with the name of an existing lambda function entrypoint, instead of a redirect, a black redirect error page will be shown

This is due to a missing Location: <new-location> in the server response.

When requesting /home and there is a lambda function called home; Location is missing from the 301 call.

Trying to request for /contactttt, there is no lambda function called contactttt. Location: /contactttt/ is returned along with the 301 status code.

> GET /contactttt HTTP/1.1
> Host: ibcol-dev.bbi.now.sh
> User-Agent: insomnia/6.3.2
> Accept: */*


< HTTP/1.1 301 Moved Permanently
< Date: Thu, 09 May 2019 12:22:32 GMT
< Content-Type: text/plain
< Transfer-Encoding: chunked
< Connection: keep-alive
< Location: /contactttt/
< x-now-trace: hkg1
< server: now
< x-now-id: cc5zz-1557404552231-c1a8dc9ffe4c02d2944c8a0f152f591e
< strict-transport-security: max-age=63072000
< cache-control: s-maxage=0
< Strict-Transport-Security: max-age=31536000; includeSubDomains;

> GET /contact HTTP/1.1
> Host: ibcol-dev.bbi.now.sh
> User-Agent: insomnia/6.3.2
> Accept: */*

< HTTP/1.1 301 Moved Permanently
< Date: Thu, 09 May 2019 12:18:01 GMT
< Content-Type: text/plain
< Transfer-Encoding: chunked
< Connection: keep-alive
< x-now-trace: hkg1
< server: now
< x-now-id: cc5zz-1557404281424-5b206880e8e96b5e3e268db9fa7df095
< strict-transport-security: max-age=63072000
< cache-control: s-maxage=0
< Strict-Transport-Security: max-age=31536000; includeSubDomains;

Workarounds

  1. Renaming the lambda function
  2. Move the lambda functions inside a subfolder, for NextJS, this can be done by adding a sub folder to /pages/.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment