GithubHelp home page GithubHelp logo

boilerplate's People

Contributors

augnin avatar devinivy avatar wswoodruff avatar zemccartney avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

boilerplate's Issues

Readme revamp

The readme needs to be cleaned-up a bit. Also worth describing some ideas around plugin/server separation and why the boilerplate is constructed the way it's constructed.

anything you'd do different?

Hi,

I just stumbled upon your boilerplate -- is there anything you'd do differently since this was last updated?

Cheers!

Add Sequelize support as flavor

I saw that you offer knex and objection support but what do you think of adding Sequelize support as flavor as well?

I could definitely look into making a PR if that's something you'd consider.

Thanks for the great project.

Comment a bit on boilerplate structure

Could you comment a bit, in your opinion, what should the plugins and methods directories contain.

Methods are route handlers? And plugins should contain code for modules that are not route handlers?
Maybe update tutorial a bit.

Flavors are less informal then it would seem

It should say what each one does instead of having to click on each projects link and read through their stuff.

In that you could have recipes so mixing flavors makes something of common request. Example
Vanilla + Eggs + Ice + sugar = make Magic server that generates chill QR codes I guesses like

Can you mix flavors?

Not really clear, I would like to have a hapi with

  • Rest API with Swaggwer
  • Postgresql with ORM
  • templated handlebars site

Is it possible to just run all flavors on top of each other ?

Joi validation with mongoose models

I've set up a project using the docs guide and I have a route set up like so

{
    method: 'POST',
    path: '/',
    options: {
        validate: {
            payload: {
                name: Joi.string().required()
            }
        },
        handler: async (request, h) => {
        }
    }
}

However this throws an error

Error: server.route() called by haute using /api/lib/routes/parent.js: Cannot set uncompiled validation rules without configuring a validator

This makes sense because unlike the Schwifty models, the mongoose models don't have Joi validation integrated. Can the documentation be updated to show how this can be done with mongoose models?

Add sub-documents from another file (mongoose)

I have 2 mongo models defined in 2 different files (generated using hpal make model like so

models/parent.js

'use strict';

const Mongoose = require('mongoose');

module.exports = {
    name: 'parent',
    schema: new Mongoose.Schema({
        name: String,
        age: Number
      })
};

models/child.js

'use strict';

const Mongoose = require('mongoose');

module.exports = {
    name: 'child',
    schema: new Mongoose.Schema({
        name: String,
        age: Number
      })
};

What I'm trying to do is define child as a sub-document array on parent but it throws an error

'use strict';

const Mongoose = require('mongoose');
const Child = require('./child');

module.exports = {
    name: 'parent',
    schema: new Mongoose.Schema({
        name: String,
        age: Number,
        children: [Child]
      })
};

TypeError: Invalid schema configuration: Child is not a valid type at path name. See http://bit.ly/mongoose-schematypes for a list of valid schema types.

Pretty sure something needs to be different in the require statement but not quite sure what it is.

Safer, cleaner server defaults

Running on a host of 0.0.0.0 is not a safe default because it could inadvertently expose the app over the network. It's also not suggested to run nodejs without a reverse proxy or similar in front of it. Second, our debug defaults are redundant (implementation and internal tags both always come with an error tag) and introduce the NODE_ENV value 'development' which is not necessary or particularly 12 factor.

it's really not an issue but i need your help

i am new in hapi and i really like your boilerplate api but i don't know how can i add plugin
for example i want to add hapi-io plugin for socket and i should put this lines
server.register({
register: require('hapi-io'),
options: {
...
}
});

exports.register = function(server, options, next) {

var io = server.plugins['hapi-io'].io;

};

where should i put them

migrations location

Hi again! Was your intention for the migrations directory to live under lib/?

Investigate swagger flavor CORS issue

It appears that swagger UI makes requests not to the current host but instead server.info.host, which can cause CORS issues. This is most typically seen when running the server at 0.0.0.0 but browser swagger UI on localhost.

hapi 17 comptability?

heyo!

now that h17 is out, i was thinking about starting from the boilerplate and re-structuring my application a bit using this boilerplate. any thoughts on h17 compatibility?

cheers,
james

The concepts of 'view-model', 'controller', and 'adapter/mapper' are missing from the boilerplate/hpal/ hapipal-realworld-example-app

Not sure if this subproject is the best place for this (maybe it'd be hpal; please let me know), but right now, the aforementioned concepts are missing and that represents a big problem from the separation of concerns PoV.

Right now, what's the best way to create a view-model (say, a REST resource/DTO that is different from the Schwifty model and has different Joi validations, etc.?
What about a translation layer responsible for converting between view-model and model?
What about the logic inside the handler of a route? (IMHO, it'd be useful to have a controller abstraction for just that, but maybe the expectation is that we'll use a Schmervice service for it and also for adapter/mapper implementations if we want to separate things?)

I know things are usually kept simpler in Node/Hapi projects when compared to, let's say, a Java project, but I can't see a proper separation of concerns without at least the inclusion of the view-model concept.

Cannot migrate/rollback in tests

Hi,

I created a project using boilerplate and schwifty. When I try to use server.knex().migrate in test file, it is looking project/migrations instead of project/lib/migrations and I got following error:

ENOENT: no such file or directory, scandir '.....project/migrations

test/01-test.js

const Code = require("code");
const Lab = require("lab");
const Server = require("../server");
const Package = require("../package.json");

const { describe, it, beforeEach, before } = (exports.lab = Lab.script());
const { expect } = Code;

let server;

before(async () => {
  server = await Server.deployment();
});

beforeEach(async () => {
  const knex = await server.knex();
  await knex.migrate.rollback();
  await knex.migrate.latest();
  await knex.seed.run();
});

describe("Deployment", () => {
  it("registers the main plugin.", async () => {
    expect(server.registrations[Package.name]).to.exist();
  });
});

lib/plugins/schwifty
There is no lib like it is swallowed:
Produces ENOENT: no such file or directory, scandir '.....project/migrations

module.exports = {
  plugins: {
    options: {
      migrationsDir: `${__dirname}/../migrations`,
    },
  },
};

Additional notes:

  • Builtin schwifty migration works as expected in tests.
  • npx knex migrate:rollback works as expected
  • File locations are as default created by hapipal.

Thanks

Calling Plugin Route Handler from App Handler

service-x/
├── lib/
│   ├── routes
│	├── get-student.js
│   	├── new-student.js
│
├── server/

service-y/
├── lib/
├── server/


service-z/
├── lib/
├── server/

gateway-service/
├── lib/
│   ├── routes
│		├── gw-get-student.js
│		├── gw-new-student.js
│   ├── plugins
│		├── service-x.js
│		├── service-y.js
│		├── service-z.js
├── server/

Service-x, y and z are micro services. "gateway-service" act as proxy/gateway service to all other services.

I want to add all the "x/y/z" services as a plugin to "gateway-service". And for that, I created files in "lib/plugins" directory and its registered successfully.

But I am not sure how do I call the "service-x" route handler from "gateway-service" handler. !!!!

Can you please help me on this?

I designed this way, so that initially i will deploy the App as one Monolithic app. If required I can deploy as individual micro service as well. Is this design is correct ?

logic in handlers

It's your favorite person again! lol

This may be something that's personal preference, but curious where you store most of your business logic? Are you doing most things in your handlers or do you store logic in your Objection models?

For example, with my other project, the vast majority of my logic lies in my models -- making the handlers very light.

Again, just trying to weed out some best practices. I realize there's many ways to do things, but it's always good to hear from others!

Not Clear That You Can't Continue From Getting Started to Flavors

In the readme after completing Getting Started section I continue to Flavors:

  1. hpal new my-project
  2. cd ./my-project
  3. git cherry-pick templated-site
    error: refusing to lose untracked file at 'server/manifest.js'
  4. git add -A :/, git commit -m "blabla"
  5. git cherry-pick templated-site
    error: after resolving the conflicts, mark the corrected paths

If I have to run git clone instead of hpal new my-project then it's not clear from the readme.
Thank you for your work.

Set server debug options

When NODE_ENV is set to 'dev', enable server debug mode. We need to settle on which tags to log. Debug will by default be preferred over good logging in this environment.

How to test?

Hi,

I would like to test a hapipal project that uses Schwifty. I could create simple unit tests for the Schwifty models without actually requiring the server at all, but when I would like to test my routes I don't know how to get

  • the models loaded
  • migrations runs properly
  • (and possibly) the server not listening

Example router:

'use strict'
const Joi = require('joi')

const handler = async function (request, h) {
  // console.log('realm2', request.route.realm)
  console.log('models', request.models())
  const { Championship } = request.models()
  const rounds = await Championship.query()
    .eagerAlgorithm(Championship.JoinEagerAlgorithm)
    .eager('[matches(orderByCode).[guest_team, home_team], children, main]')
    .findById(request.params.championshipId)
  return rounds
}

module.exports = {
  method: 'GET',
  path: '/championships/{championshipId}',
  config: {
    auth: false,
    validate: {
      params: {
        championshipId: Joi.number()
      }
    }
  },
  handler
}

and the accompanying test (as I imagine it) would start somehow like:

'use strict'

const Server = require('../../../server')

// Load modules
const Championship = require('../../models/Championship')
const config = require('../championship-get')

// Test shortcuts

describe('Championship get', () => {
  let server
  beforeAll(async () => {
    server = await Server.deployment(false)  // I prefer not to listen in a test
    await server.knex().migrate.latest('../lib/migrations')  // migrations should run as per manifest, but they don't, and setting the path here is ignored for some reason
    server.route(config)
  })

  beforeEach(async () => {
    await Championship.query(server.knex()).insert({
      name: 'WSB 2018'
    })
  })

  test('calls its handler', async () => {

    const res = await server.inject({
      method: 'GET',
      url: '/championships/1',
      headers: {}
    })

    expect(res.statusCode).toEqual(200)
  })
})

The above fails as request.models() is empty.

I've figured out that models are to be parsed at the onPreStart event, but I would not start a server when I'm testing. Is there a way to still access models in requests?

Update deployment flavor

I just boostrapped a project using the CLI and used the deployment flavor. I noticed the flavor is not using the @hapi scoped package. I'd be happy to update it but I wondered what is the preferred workflow for it. I noticed there is a flavor-deployment branch and also the tag we cherry-pick. My guess is that you make the change on the branch, commit and after that you update the deployment tag (if I have the right to do it) on the HEAD of that branch, is that correct?

Thanks 👍

Add uglify to templated site flavors

The templated site and fancy templated site flavors use uglify to create production JS builds. Currently this works because handlebars depends on uglify, but we should also depend on it explicitly.

knex setup for integration testing

do you have a good system for using Knex for integration testing? Specifically curious how you go about resetting the database before every test. I've tried a few things but running into gotchas!

Note: I felt like this was relevant to the boilerplate, but if you don't, feel free to close 😄

Update dependencies with new @hapi scope

Modules in the hapijs org now are published under the @hapi/x scope. References to these dependencies need to be updated. This would also be a good time to ensure deps are up to date. I believe the only one needing updating will be joi. Also need to sweep flavors.

How to get testing up and working

I'm new to node and I'm checking out your repo...thanks!! I have everything up and running but I can't see to get testing going.

I'm assuming that since your are exporting the manifest in server.js that you would create the server via Glue in each of your test files. Whenever I do this it never calls the callback passed to Glue.compose

Am I setting this up right?

// test/test.js

var Glue = require('glue');
var Path = require('path');

var manifest = require("../server.js");

Glue.compose(manifest, { relativeTo: Path.join(__dirname, '../node_modules') }, function (err, server) {

   // We never get here..

    if (err) {
        throw err;
    }

    console.log('begin tests');  

});

Test Output:

0 tests complete
Test duration: 0 ms
No global variable leaks detected

Add linting

I'm going to play with adding eslint to the chalice-api, and it seems like it might be worth adding in here too, thoughts, @devinivy ? If I get it working, I'd be happy to put together a PR.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.