Last active
December 2, 2016 18:25
-
-
Save joyrexus/a4e798f0a3a89231b44452767b9c1305 to your computer and use it in GitHub Desktop.
hapi redirect demo
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
'use strict'; | |
const Hapi = require('hapi'); | |
const server = new Hapi.Server(); | |
server.connection({ | |
host: 'localhost', | |
port: 8000 | |
}); | |
server.route({ | |
method: 'GET', | |
path:'/hello', | |
handler: function (request, reply) { | |
return reply().redirect(`${server.info.uri}/next?foo=bar`); | |
} | |
}); | |
server.route({ | |
method: 'GET', | |
path:'/next', | |
handler: function (request, reply) { | |
return reply(request.query); | |
} | |
}); | |
// Start the server | |
server.start((err) => { | |
if (err) { | |
throw err; | |
} | |
console.log('Try', `${server.info.uri}/hello`); | |
}); |
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
{ | |
"name": "hapi-redirect", | |
"version": "1.0.0", | |
"description": "quick demo of how to redirect w/ querystring", | |
"main": "index.js", | |
"keywords": [ | |
"hapi", | |
"redirect", | |
"demo" | |
], | |
"author": "joyrexus", | |
"license": "MIT", | |
"dependencies": { | |
"hapi": "^16.0.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment