Created
March 14, 2014 08:10
-
-
Save jameswyse/9543832 to your computer and use it in GitHub Desktop.
Hapi Server Test
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
var Hapi = require('hapi'); | |
// Create a server with a host and port | |
var server = Hapi.createServer('localhost', 8000); | |
// Basic HTML form template | |
var form = '<!doctype html> \ | |
<html> \ | |
<head> \ | |
<title>Test</title> \ | |
</head> \ | |
<body> \ | |
<form action="/test" method="post"> \ | |
<input type="text" name="one" id="one" value="first field"> \ | |
<input type="text" name="two" id="two" value="second field"> \ | |
<button type="submit">Submit</button> \ | |
</form> \ | |
</body> \ | |
</html>'; | |
// GET / | |
server.route({ | |
method: 'GET', | |
path: '/', | |
handler: function (request, reply) { | |
reply(form); | |
} | |
}); | |
// POST /test | |
server.route({ | |
method: 'POST', | |
path: '/test', | |
handler: function (request, reply) { | |
reply(request.payload); | |
} | |
}); | |
// Start the server | |
server.start(); |
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-passenger-test", | |
"version": "0.0.1", | |
"description": "Testing Hapi with Passenger", | |
"main": "app.js", | |
"author": "James Wyse <[email protected]>", | |
"license": "MIT", | |
"dependencies": { | |
"hapi": "^3.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment