Skip to content

Instantly share code, notes, and snippets.

@mtharrison
Created November 2, 2015 11:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mtharrison/eb771b4a2bace5a639c9 to your computer and use it in GitHub Desktop.
Save mtharrison/eb771b4a2bace5a639c9 to your computer and use it in GitHub Desktop.
127.0.0.1 example.com
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>2FA Example</title>
</head>
<body>
<h1>Hello there!</h1>
<script type="text/javascript">
var request = new XMLHttpRequest();
request.open('POST', 'http://example.com', true);
request.setRequestHeader('Content-Type', 'application/json');
request.send('');
</script>
</body>
</html>
var Glue = require('glue');
var Hapi = require('hapi');
var manifest = {
connections: [
{
port: 80
}
],
plugins: {
'inert': null,
'./web': [{
routes: {
vhost: 'example.com'
}
}]
}
};
var options = {
relativeTo: __dirname
};
Glue.compose(manifest, options, function (err, server) {
if (err) {
throw err;
}
server.route({
method: 'GET',
path: '/',
config: {
handler: function (request, reply) {
reply.file('index.html');
}
}
});
server.start(function () {
console.log('Hapi days!');
});
});
{
"name": "cors",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"glue": "^2.4.0",
"hapi": "^11.0.3",
"inert": "^3.2.0"
}
}
exports.register = function (server, options, next) {
server.route({
method: 'POST',
path: '/',
config: {
cors: {
origin: ['*'],
additionalHeaders: ['content-type']
},
handler: function (request, reply) {
reply('ok');
}
}
});
next();
};
exports.register.attributes = { name: 'web', version: '1.0.0' };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment