Loading certain slices leads to errors in the routes. How to work around this?

Hey :wave: ,

I only want to load certain slices. I set the environment variable “SLICES” to e.g.

HANAMI_SLICES="admin"

My routes.rb looks like this:

# frozen_string_literal: true

module Services
  class Routes < Hanami::Routes
    root { "Hello from Services" }

    slice :test, at: "/test" do
      scope :graphql do
        use :body_parser, :json
        use Services::Middlewares::Authorization
        post "/api", to: "graphql.api"
      end
    end

    slice :admin, at: "/admin" do
      scope :graphql do
        use :body_parser, :json
        use Services::Middlewares::Authorization
        post "/api", to: "graphql.api"
      end
    end
  end
end

If a request is now made on /admin, an error occurs.

2023-11-21 07:41:07 +0100 Rack app ("POST /admin/graphql/api" - (172.30.0.1)): #<Hanami::SliceLoadError: Slice 'test' not found>

How to work around this?

Thanks!

See this topic

2 Likes

The funny thing is that I actually read this post of yours months ago, but couldn’t remember it.
Thanks!

1 Like