Skip to content

Commit b156a8a

Browse files
committed
add example: redirect POST requests and keep payload
1 parent d5fb755 commit b156a8a

3 files changed

Lines changed: 73 additions & 0 deletions

File tree

hapi-18/.eslintrc.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"env": {
3+
"es6": true,
4+
"node": true
5+
},
6+
"extends": [
7+
"standard"
8+
],
9+
"plugins": [
10+
"standard"
11+
],
12+
"parserOptions": {
13+
"ecmaVersion": 2018
14+
}
15+
}

hapi-18/package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "hapi-18",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "MIT",
12+
"dependencies": {
13+
"@hapi/hapi": "~18.3.1"
14+
},
15+
"devDependencies": {
16+
"eslint": "~6.0.1",
17+
"eslint-config-standard": "~13.0.1",
18+
"eslint-plugin-import": "~2.18.0",
19+
"eslint-plugin-node": "~9.1.0",
20+
"eslint-plugin-promise": "~4.2.1",
21+
"eslint-plugin-standard": "~4.0.0"
22+
}
23+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict'
2+
3+
const Hapi = require('@hapi/hapi')
4+
5+
const server = new Hapi.Server({
6+
host: 'localhost',
7+
port: 3000
8+
})
9+
10+
async function start() {
11+
server.route([
12+
{
13+
method: 'POST',
14+
path: '/',
15+
handler: (_, h) => {
16+
return h.redirect('/new').code(307)
17+
}
18+
},
19+
{
20+
method: 'POST',
21+
path: '/new',
22+
handler: ({ payload }) => {
23+
return {
24+
message: 'Received your request including the payload!',
25+
payload
26+
}
27+
}
28+
}
29+
])
30+
31+
await server.start()
32+
console.log('Server running on %s', server.info.uri);
33+
}
34+
35+
start()

0 commit comments

Comments
 (0)