Created
November 2, 2015 11:29
-
-
Save mtharrison/eb771b4a2bace5a639c9 to your computer and use it in GitHub Desktop.
Example for https://github.com/hapijs/glue/issues/38
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
127.0.0.1 example.com |
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
<!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> |
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 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!'); | |
}); | |
}); |
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": "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" | |
} | |
} |
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
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