Instantly share code, notes, and snippets.

Embed
What would you like to do?
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