Eexpressjs

expressjs/back-redirect-deprecated

Migrates usage of the legacy APIs `res.redirect('back')` and `res.location('back')` to the current recommended approaches

transformationmigrationexpressredirectlocation
Public
5 executions
2 stars
How to Use
Run this codemod on your codebase using one of the following commands

The easiest way to run this codemod without installing anything globally:

Documentation

Migrate legacy res.redirect('back') and res.location('back')

Migrates usage of the legacy APIs res.redirect('back') and res.location('back')
to use the recommended approach of accessing the Referer header directly from
the request object. Versions of Express before 5 allowed the use of the string
"back" as a shortcut to redirect to the referring page, but this has been
deprecated.

Example

Migrating res.redirect('back')

The migration involves replacing instances of res.redirect('back') with res.redirect(req.get('Referer') || '/').

diff

Migrating res.location('back')

The migration involves replacing instances of res.location('back') with res.location(req.get('Referer') || '/').

diff

References

Ready to contribute?

Build your own codemod and share it with the community.