Skip to content

Instantly share code, notes, and snippets.

@jameswyse
Created March 14, 2014 08:10
Show Gist options
  • Save jameswyse/9543832 to your computer and use it in GitHub Desktop.
Save jameswyse/9543832 to your computer and use it in GitHub Desktop.
Hapi Server Test
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();
{
"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