Aucune description

server.js 719B

12345678910111213141516171819202122232425262728293031323334353637
  1. const Hapi = require('hapi')
  2. const server = new Hapi.Server({ port: 8080, host: 'localhost' })
  3. const init = async () => {
  4. await server.register([
  5. require('inert'),
  6. {
  7. plugin: require('hapi-pino'),
  8. options: {
  9. prettyPrint: true,
  10. logEvents: ['response', 'onPostStart']
  11. }
  12. }
  13. ])
  14. server.route({
  15. method: 'GET',
  16. path: '/{param*}',
  17. handler: (request, h) => h.file('./' + request.path)
  18. })
  19. server.route({
  20. method: 'GET',
  21. path: '/',
  22. handler: (request, h) => h.file('./index.html')
  23. })
  24. await server.start()
  25. console.log(`Server running at: ${server.info.uri}`)
  26. }
  27. process.on('unhandledRejection', err => {
  28. console.log(err)
  29. process.exit(1)
  30. })
  31. init()