Skip to content

Instantly share code, notes, and snippets.

@josser
Created March 9, 2021 16:16
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 josser/1139ade3432e7ccad17237b2ea9f1c0d to your computer and use it in GitHub Desktop.
Save josser/1139ade3432e7ccad17237b2ea9f1c0d to your computer and use it in GitHub Desktop.
<!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>
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