Skip to content

hmdc/redirect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

redirect

This web app returns 301 redirect from src regexp to destination defined in config/default.json using ririd.

adding a redirect

  • Open config/default.js
  • Add an entry under redirectMap conforming to the already existing examples. You can add and set the elements withPath and withQs, which strip paths or query strings when redirecting to the destination. By default, withPath and withQs is set to true.
module.exports = {
    "defaultRedirect": "https://www.iq.harvard.edu",
    "port": process.env.PORT || 3000, // required for heroku
    "redirectMap": [
        { "src": "^(.*\\.)cga\\.harvard\\.edu$", "dst": "https://www.gis.harvard.edu", "withPath": false },
    ]
}

The above will redirect all requests to http[s]://*.cga.harvard.edu to https://www.gis.harvard.edu stripping the path. Requests to http[s]://*.cga.harvard.edu/a/b/c are redirected to http[s]://*.cga.harvard.edu.

deleting a redirect

Remove the element from the array above.

testing

You can run this localy to test.

Presume you're using the above example.

You need NodeJS installed!

run

npm install; npm start

You only need to run npm install once or when changes are present in package.json or lock.

You can now run curl and check that the redirect works

curl -o /dev/null -s -w '%{url_effective} %{redirect_url}\n' http://localhost:3000/a/b/c/d -H 'Host: abc.cga.harvard.edu'
http://localhost:3000/a/b/c/d https://www.gis.harvard.edu/a/b/c/d

As you can see, the request is successfully redirected.

deploying to heroku

app name hmdc-www6-legacy-redirect hostname hmdc-www6-legacy-redirect.hmdc.harvard.edu

Typically when we redirect sites, we set the CNAME to www6-vm1.hmdc.harvard.edu or www.hmdc.harvard.edu in the noc portal.

If your tests pass, you can just push to the heroku origin first

git push origin heroku

When migrating a redirect to Heroku, you should add the domain

heroku domains:add any.domain.name

example

heroku domains:add cga.harvard.edu

You can then CNAME cga.harvard.edu to the Heroku ssl target endpoint printed and reload SSL settings every so often until the CNAME is propaated and a new LetsEncrypt cert is generated by Heroku for the domain.

Then you can test (again) live.

app creation steps (no need to perform these steps again, listed for posterity)

heroku apps:create -t g-harvard hmdc-www6-legacy-redirect git push heroku

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published