hapijs / glue

Server composer for hapi.js
Other
245 stars 62 forks source link

Update Api.md documentation #105

Closed samueljoli closed 7 years ago

samueljoli commented 7 years ago
'use strict';

const Glue = require('glue');

const manifest = {
    server: {
        cache: 'redis',
        port: 8000
    },
    register: {
        plugins: [
            './awesome-plugin.js',
            {
                plugin: require('myplugin'),
                options: {
                    uglify: true
                }
            },
            {
                plugin: './ui-user'
            },
            {
                plugin: './ui-admin',
                options: {
                    sessiontime: 500
                },
                routes: {
                    prefix: '/admin'
                }
            }
        ]
    }
};

const options = {
    relativeTo: __dirname
};

try {
    const server = await Glue.compose(manifest, options); //.. will throw an error. 
    await server.start();
    console.log('hapi days!');
}
catch (err) {
    console.error(err);
    process.exit(1);
}

This would throw a SyntaxError: Unexpected identifier error since await is being called outside of an async function.

I could throw together a quick PR to fix this.

Maybe something like

'use strict';

const Glue = require('glue');

const manifest = {
    server: {
        cache: 'redis',
        port: 8000
    },
    register: {
        plugins: [
            './awesome-plugin.js',
            {
                plugin: require('myplugin'),
                options: {
                    uglify: true
                }
            },
            {
                plugin: './ui-user'
            },
            {
                plugin: './ui-admin',
                options: {
                    sessiontime: 500
                },
                routes: {
                    prefix: '/admin'
                }
            }
        ]
    }
};

const options = {
    relativeTo: __dirname
};

const startServer= async function () {
  try {
      const server = await Glue.compose(manifest, options);
      await server.start();
      console.log('hapi days!');
  }
  catch (err) {
      console.error(err);
      process.exit(1);
  }
}

startServer(); 
lock[bot] commented 4 years ago

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.