Created
January 25, 2018 14:25
-
-
Save timoweiss/f268d4d6828f5a147943bfe51b3b92b3 to your computer and use it in GitHub Desktop.
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": "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" | |
} | |
} |
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
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