Skip to content

Instantly share code, notes, and snippets.

@joyrexus
Last active December 2, 2016 18:25
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 joyrexus/a4e798f0a3a89231b44452767b9c1305 to your computer and use it in GitHub Desktop.
Save joyrexus/a4e798f0a3a89231b44452767b9c1305 to your computer and use it in GitHub Desktop.
hapi redirect demo
'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`);
});
{
"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