Created
March 9, 2021 16:16
-
-
Save josser/1139ade3432e7ccad17237b2ea9f1c0d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Document</title> | |
</head> | |
<body> | |
<script> | |
fetch('/first', { | |
redirect: 'follow' | |
}) | |
.then(r => { | |
console.log('---then--', r) | |
}).catch(e => { | |
console.log('in the catch') | |
}) | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { promises: fs } = require('fs') | |
const Koa = require('koa') | |
const Router = require('@koa/router') | |
const app = new Koa() | |
const redirects = new Router() | |
redirects.get('/first', ctx => { | |
ctx.redirect('/second') | |
}) | |
redirects.get('/second', ctx => { | |
ctx.redirect('/third') | |
}) | |
redirects.get('/third', ctx => { | |
ctx.redirect('/final') | |
}) | |
redirects.get('/front.html', async ctx => { | |
ctx.response.set('content-type', 'text/html') | |
ctx.body = await fs.readFile('./index.html') | |
}) | |
app.use(redirects.routes(), redirects.allowedMethods()) | |
app.listen(3000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment