Server Start issue #8

Closed
opened 2016-07-12 07:55:53 +00:00 by casalot · 2 comments
casalot commented 2016-07-12 07:55:53 +00:00 (Migrated from github.com)

The following is an extract from my server.js script:

const Hapi = require('hapi');
const server = new Hapi.Server();
const Sequelize = require('sequelize');

/* Register all required plugins */
server.register([{
  { ... all other plugins in here ... },
  {
    register: require('hapi-sequelize'),
    options: [
      {
        name: 'agrade',
        models: ['./api/models/seq/*.js'],
        sequelize: new Sequelize('a-grade', 'root', '', {
          host: 'localhost',
          port: 3306,
          dialect: 'mysql'
        })
      }
    ]
  }], (err) => {
    if (err) {
      console.log('ERROR:', err);
    };
    let db = server.plugins['hapi-sequelize'].agrade;
    let models = db.sequelize.models;
    //associations(models);

    server.register({
      register: require('hapi-sequelize-crud'),
      options: {
        prefix: '/api/seq'
      }
    });

    var routes = require(appDir + process.env.PATH_API + process.env.PATH_ROUTES);
    server.route(routes);

    server.start(() => {
      logger.log('info',`SERVER - server STARTED`);
    });

  });

I'm not sure where to register the hapi-sequelize-crud plugin.

When it is as the code above, the server starts up without errors, but none of my routes work (not routes generated by hapi-sequelize-crud, or manually created routes).

When I add it immediately after the hapi-sequelize registration, I get the following error: "Cannot read property 'sequelize' of undefined" or server startup.

The following is an extract from my `server.js` script: ``` javascript const Hapi = require('hapi'); const server = new Hapi.Server(); const Sequelize = require('sequelize'); /* Register all required plugins */ server.register([{ { ... all other plugins in here ... }, { register: require('hapi-sequelize'), options: [ { name: 'agrade', models: ['./api/models/seq/*.js'], sequelize: new Sequelize('a-grade', 'root', '', { host: 'localhost', port: 3306, dialect: 'mysql' }) } ] }], (err) => { if (err) { console.log('ERROR:', err); }; let db = server.plugins['hapi-sequelize'].agrade; let models = db.sequelize.models; //associations(models); server.register({ register: require('hapi-sequelize-crud'), options: { prefix: '/api/seq' } }); var routes = require(appDir + process.env.PATH_API + process.env.PATH_ROUTES); server.route(routes); server.start(() => { logger.log('info',`SERVER - server STARTED`); }); }); ``` I'm not sure _where_ to register the `hapi-sequelize-crud` plugin. When it is as the code above, the server starts up without errors, but none of my routes work (not routes generated by `hapi-sequelize-crud`, or manually created routes). When I add it immediately after the `hapi-sequelize` registration, I get the following error: "**Cannot read property 'sequelize' of undefined**" or server startup.
casalot commented 2016-07-12 11:25:47 +00:00 (Migrated from github.com)

Okay, I have figured this out. Two issues:

  1. babel-polyfill missing
  2. the hapi-sequelize db name is hardcoded as 'db'
Okay, I have figured this out. Two issues: 1. `babel-polyfill` missing 2. the `hapi-sequelize` db name is hardcoded as '**db**'
mdibaiee commented 2016-07-12 15:04:55 +00:00 (Migrated from github.com)

@casalot: Hey, you're right about db name being hardcoded, I wasn't aware of such feature.
We're most probably going to switch to Babel 6 here.

@casalot: Hey, you're right about db name being hardcoded, I wasn't aware of such feature. We're most probably going to switch to Babel 6 [here](https://github.com/mdibaiee/hapi-sequelize-crud/pull/5).
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: thereadme/hapi-sequelize-crud#8
No description provided.