Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Jon Swenson
    @zoe-1
    Hope you get things working @smahi :-)
    Jon Swenson
    @zoe-1

    If you are using aurelia.js library to make ajax requests. Check it's documentation on how it sets headers and cookies. Make sure you are doing it the aurelia way. Note: I never used the library.

    IMHO, choose reactjs when possible.
    And, if you feel like exploring and trying something else checkout elm-lang.

    Abesse Smahi
    @smahi
    @zoe-1 I've already a passing test in place for route in the backend and i am appending the headers with 'x-csrf-token' in the frontend the right way of Aurelia using interceptor of the aurelia-fetch-client api.
    @zoe-1 i noticed that there is no cookie cookie: 'crumb=' + crumb (i have checked it in chrome devtool > application section > Cookie) but instead 'set-cookie' entry in headers
    Jon Swenson
    @zoe-1
    Does 'x-csrf-token': xxxxxxxx
    exist in the headers?
    Abesse Smahi
    @smahi
    @zoe-1 yes
    Jon Swenson
    @zoe-1

    See docs:
    https://github.com/hapijs/crumb

    read about using skip with a route.

    set crumb to not be used on the route then
    debug the request.
    see what headers and cookies are being set etc.
    If you already have your tests passing for each route. Then, you are really close to solving this.
    Abesse Smahi
    @smahi

    @zoe-1 this did not work

    plugins:{
                  crumb:{
                      skip: function(request, reply){ return true }
                  }
                },

    but this worked

    plugins:{ crumb: false }
    @zoe-1 when setting crumb option restful: true do i have to set both headers entries x-crsf-token and cookie in client side ?
    Jon Swenson
    @zoe-1
    try skip: true;
    Or, just turn off crumb's use.
    The goal is to see the request your browser is sending to the server.
    Abesse Smahi
    @smahi
    @zoe-1 this in route config plugins:{ crumb: false } will turn of crumb for a specific route
    @zoe-1 and i've tested it it works
    Jon Swenson
    @zoe-1
    Great glad you got turned off.
    now, you can inspect the request coming from the browser.
    Abesse Smahi
    @smahi
    @zoe-1 the route send an email, and i am using maildev package to test emails
    @zoe-1 when i turn off crumb i receive the email :smile:
    Jon Swenson
    @zoe-1
    just make another route and send the request there.
    Abesse Smahi
    @smahi

    @zoe-1 this are comments from crumb repo example code

    // a "crumb" cookie should be set with any request
        // for cross-origin requests, set CORS "credentials" to true

    what did the maintainer mean ?

    Jon Swenson
    @zoe-1

    It is talking about two ways to make requests.

    First, requests made to the same origin.
    client domain is same as server domain.
    hapijs/university requests are same origin.

    Second, making requests to a different origin/domain. Here, The client domain is different from server domain.
    This is CORS (cross origin resource sharing).
    By default browsers block CORS requests. So, we need to tell the browser to allow CORS from the specific domains we want to use. Plus, we need to make sure crumb is configured to work properly with the CORS request.

    Most bigger projects have one web api serving data to different applications (web client / browser, hand held devices, command line applications, etc).
    The docs are explaining what needs to be done when configuring CORS and crumb.

    A sample project using CORS would be:
    1) client server which serves a SPA (single page application)or hybrid of a SPA. This is where all your client logic would be. (front end development) The domain would be:
    mystore.com -> 199.999.988
    2) web api which serves data to the client.
    Receives RESTFUL HTTP requests and returns JSON data.
    api.mystore.com -> 199.999.987
    (This is a different application than the client)

    In the above sample, the client would have to be configured to make CORS requests to api.mystore.com. If the configuration is not done properly the browser will block requests made to the different domain (api.mystore.com)

    See:
    https://hapijs.com/api#route-options
    https://www.w3.org/TR/cors/
    https://en.wikipedia.org/wiki/Cross-origin_resource_sharing

    It is worth investing time to read up on CORS.
    Plus, it would be helpful to build a small CORS sample of a client consuming an api. You can do it on your local machine. Requests made to a different PORT are also considered cross origin.

    Jon Swenson
    @zoe-1
    @smahi hope your project goes well!
    I am going out for a bit.
    bye :-)
    Abesse Smahi
    @smahi
    @zoe-1 sorry i was away, thank you for your explanation and for your help
    Roger Schlachter
    @RogerSchlachter_twitter

    Hi, I'm using hapi to develop an API. I'm currently using the require-hapiroutes plugin (https://www.npmjs.com/package/require-hapiroutes) to make adding routes easy since we're still adding a bunch of new routes. Now a requirement has come in that we have to prefix all of our routes. This feels like it should be a fairly simple thing, but it doesn't seem like it is. Am I missing something simple? So far it looks like I either have to mutate the routes manually something like this:

    let routes = require('./app/route');
    
    routes.routes = _.map(routes.routes, (route) => { //I don't like mutating data in map function but...
        route.path = "/myprefix" + route.path;
        return route
    });
    
    server.route(routes.routes);

    or I need to somehow turn my routes into a plugin so that I can then register that plugin and then give the routes a prefix that way. Is there recommended/preferred way to handle that?

    Jon Swenson
    @zoe-1

    @RogerSchlachter_twitter
    In respect to using the npmjs package hapiroutes,
    it looks a bit out dated. Last commit was in 2015.

    In respect to hapi and adding routes to your application or plugin, hapi let's you define routes as an object or array of objects. You do not need that plugin.

    See below for references:

    Trung Hieu Nguyen
    @hieunguyen135
    hi
    Jon Swenson
    @zoe-1
    @hieunguyen135
    Hi.
    Jon Swenson
    @zoe-1
    Was away from programming for about a week. Good to be back.
    Devan Thakur
    @iamplugged
    Hi! I am registering a plugin with a couple of routes in my server.js. Getting this error: Error: Cannot add a route without any connections
    Any idea about this error?
    Devan Thakur
    @iamplugged
    Ignore..figured it out
    Luis Carlos Osorio Jayk
    @Ciul
    @Ciul
    Hi there,
    wanted to ask what do you think about using async/await functions to register plugins
    https://jsfiddle.net/jq93q75v/2/
    Jon Swenson
    @zoe-1
    Hi @Ciul,
    To register plugins study assignment5
    hapi has a plugin named glue
    You want use glue to load plugins. That is the "hapi" way.
    Plus, look at assignment5's references to handling plugin dependencies.
    You can load plugins without glue. But, my preference is to use it.
    That way your project has a manifest object which declares all plugins used in your project.
    Luis Carlos Osorio Jayk
    @Ciul
    Hi @zoe-1
    Yes, I have used Glue but lacks of asynchronous plugin registration, and it also uses require instead of import. Using async/await could allow new benefits.
    Jon Swenson
    @zoe-1
    @Ciul Sounds worth looking into.
    Built a sample application modeled after your example and it worked fine.
    In respect to import versus require, what are you thinking about?
    Are you considering loading ES6 modules versus CommonJS?
    Btw: current node LTS (v6.x.x) does not support async await. But, v8 (the next one) will.
    Perhaps, you may find this article relevant.
    Luis Carlos Osorio Jayk
    @Ciul
    Thank you @zoe-1
    New question: What are the differences between hapi-auth-jwt and hapi-auth-jwt2 plugins?
    Jon Swenson
    @zoe-1

    Hi @Ciul,
    hapi-auth-jwt2:

    • is the more active project.
    • has more features.
      For example, send/store your JWT in a Cookie.

    Disclaimer: I have limited exposure to jwt2. So, if you want more details ask on the hapi channel.

    Tom Byrer
    @tomByrer
    Where can I find more tutorials or examples to learn lab testing framework to test a babel plugin please?
    Jon Swenson
    @zoe-1

    @tomByrer
    All hapi plugins use lab and code.
    university tests all use lab and code.
    https://github.com/hapijs/joi has some code in the tests that I found helpful.
    Specifically how to test try, catch, and throw with lab and code.
    https://github.com/jedireza/aqua tests hapi and react code.
    Maybe that is something like what your looking for.

    One thing to remember about lab is it does not provide an assertian library. It let's you pick that. Versus something like jest gives you everything, assertion library and test utility together.

    Luis Carlos Osorio Jayk
    @Ciul
    @zoe-1 I made a simple working example of how to do the asynchronous plugin registering splitted in different files aka modules

    server.js

    import Hapi from 'hapi'
    
    const server = new Hapi.Server()
    server.connection({
        port: 9000,
        host: 'localhost'
    })
    
    async function init() {
        const blipp = await import('./async-register-blipp')
        blipp.default(server)
    
        return server;
    }
    
    init()
        .then((server) => {
            server.start((err) => {
                if(err) {
                    throw err
                }
    
                console.log(`Server running at: ${server.info.uri}`)
            })
        })

    And then my async plugin registration, e.g. registering Blipp asynchronously:
    async-register-blipp.js

    import Blipp from 'blipp'
    
    export default (server) => 
        server.register({
            register: Blipp,
            options: {}
        })

    Obviously you could change default for another more verbose function name while exporting.

    The nice feature of this kind of implementation is that you could isolate (in a let's call it module) and add some logic for the plugin itself before and after registration.

    Take into account that you just need to export a Promise (could be your own promise) something like:

    export default (server) => {
        // Do something here
    
        return new Promise((resolve, reject) => {
            // Do even more here, e.g. use fetch against a server maybe?
    
            server.register({
                register: Blipp,
                options: {}
            }, (err) => {
                if(err) {
                    reject(err)
                }
    
                resolve(server) // To allow chaining ;)
            })
        })
    }

    Note: I am using babel so I can use await import and async functions. For that I add babel plugins:
    "syntax-dynamic-import",
    "syntax-async-functions"
    What do you think?

    Jon Swenson
    @zoe-1

    Hi @Ciul , you work looks interesting. Thank you for sharing :)
    Will have to build a server and work through your design.

    Currently, trying to write assignment9 for the university.Also working on writing an introduction to the request lifecycle and how to add extensions.
    Please look them over and share your thoughts :smile:

    Luis Carlos Osorio Jayk
    @Ciul
    That sounds really nice, I will take a look :)
    Jon Swenson
    @zoe-1
    hapijs/university assignment9 PR is up to receive comments or suggestions.
    hapijs/university#254
    Lancy Goyal
    @ignivalancy
    Sitraka Ratsimba
    @sitraka-hq
    Hi guys! I just release a hapi plugin named hapi-auto-route which automatically loads routes from directory! It's here. :smile:
    Tejus Pratap
    @tejzpr
    Hi all I just released a HapiJS+Typescript+TypeORM boilerplate with dynamic linting @ https://github.com/tejzpr/typehapily