GithubHelp home page GithubHelp logo

Comments (2)

jedireza avatar jedireza commented on May 19, 2024

Thanks for opening an issue.

This is a good question and one that I'll soon need to solve too 😉.

In another project of mine, with the help of inert, I define a directory handler for the path /public/{param*}. So essentially I put all my front-end assets (images/css/js) under one path.

I need to experiment with some different configurations, but I'd imagine that the specificity of the directory route handler would suffice.

from hapi-react-views.

jedireza avatar jedireza commented on May 19, 2024

As a follow up to this, in another project I have my static assets served with the help of inert like this:

    server.route({
        method: 'GET',
        path: '/public/{param*}',
        handler: {
            directory: {
                path: 'public',
                listing: true
            }
        }
    });

Then I have a catch-all style handler that globs everything like this:

    server.route({
        method: 'GET',
        path: '/{glob*}',
        handler: internals.routeHandler
    });

Because I use a shared route handler I defined (internals.routeHandler), I'm even able to intercept requests to specific routes for special case handling (like redirecting or querying data) and then pass them back to internals.routeHandler. Similar to:

    server.route({
        method: 'GET',
        path: '/login/{glob*}',
        config: {
            auth: {
                mode: 'try',
                strategy: 'session'
            },
            plugins: {
                'hapi-auth-cookie': {
                    redirectTo: false
                }
            }
        },
        handler: function (request, reply) {

            if (request.params.glob !== 'logout' &&
                request.auth.isAuthenticated) {

                if (request.auth.credentials.user.roles.admin) {
                    return reply.redirect('/admin');
                }

                return reply.redirect('/account');
            }

            if (!request.auth.isAuthenticated) {
                request.app.headers = {
                    'x-auth-required': true
                };
            }

            internals.routeHandler(request, reply)
        }
    });

And I'm not having any MIME type issues. I hope this helps.

from hapi-react-views.

Related Issues (20)

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.