Created
July 19, 2017 22:13
-
-
Save isaacs/15b88fb96f49ce22c1dd46733a953d8e 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
const http = require('http') | |
const firstServer = http.createServer((req, res) => { | |
console.log('firstServer request', req.url, req.headers) | |
res.setHeader('set-cookie', 'foo=bar; max-age=10000000; host=localhost:8080; SameSite=Strict') | |
res.setHeader('content-type', 'text/html') | |
res.write('<pre>') | |
res.write(JSON.stringify(req.headers, null, 2) + '\n</pre>') | |
if (req.headers.cookie) | |
res.end('<a href="' + secondServerHost + req.url + | |
'">dont click, copy this url to the address bar, '+ | |
'observe cookie vanish</a>\n') | |
else | |
res.end('<a href="' + req.url + | |
'">refresh to see cookie appear</a>\n') | |
}) | |
const secondServer = http.createServer((req, res) => { | |
console.log('secondServer request', req.url, req.headers) | |
res.statusCode = 301 | |
const redir = firstServerHost + req.url | |
res.setHeader('content-type', 'text/html') | |
res.setHeader('location', redir) | |
res.end('<a href="' + redir + '">' + redir + '</a>\n') | |
}) | |
const firstServerHost = 'http://localhost:8080' | |
const secondServerHost = 'http://127.0.0.1:8081' | |
firstServer.listen(8080, _ => { | |
secondServer.listen(8081, _=> { | |
console.log('load in chrome: ' + firstServerHost + '/test') | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment