Skip to content

Instantly share code, notes, and snippets.

@timoweiss
Created January 25, 2018 14:25
Show Gist options
  • Save timoweiss/f268d4d6828f5a147943bfe51b3b92b3 to your computer and use it in GitHub Desktop.
Save timoweiss/f268d4d6828f5a147943bfe51b3b92b3 to your computer and use it in GitHub Desktop.
{
"name": "xframeserver",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"hapi": "^16.6.2",
"inert": "4.x.x",
"vision": "4.x.x"
}
}
const Hapi = require('hapi');
const vision = require('vision');
const inert = require('inert');
const server = new Hapi.Server();
server.connection({
port: 3333,
routes: {
cors: true,
},
})
async function startProxy() {
try {
await server.register([vision, inert]);
server.route({
method: 'GET',
path: '/{param*}',
handler: {
directory: {
listing: true,
// set path
path: './'
}
}
});
server.ext('onPreResponse', (request, reply) => {
request.response.header('X-Frame-Options', 'ALLOW-FROM http://localhost:3000');
reply.continue();
});
await server.start();
console.log('Server started at:', server.info.uri);
} catch (error) {
console.error(error);
}
}
startProxy();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment