Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mix.env() usage can cause troubles in release #734

Closed
clsource opened this issue Jan 26, 2024 · 2 comments
Closed

Mix.env() usage can cause troubles in release #734

clsource opened this issue Jan 26, 2024 · 2 comments

Comments

@clsource
Copy link

Describe the bug

When using

mix surface.init --catalogue

It creates a new route in router.ex with the catalogue routes.
But it is using Mix.env() to check these routes.

if Mix.env() == :dev do
    scope "/" do
      pipe_through :browser
      surface_catalogue "/catalogue"
    end
  end

Possible Fix

We can create a new module constant @env to fetch the value at compile time
and check the value afterwards in runtime. Since Mix would no be available in runtime
at production release.

defmodule MyWeb.Router do
  use MyWeb, :router

  import Surface.Catalogue.Router
  @env Mix.env()

  ...

  if @env == :dev do
    scope "/" do
      pipe_through :browser
      surface_catalogue "/catalogue"
    end
  end

Your Environment

Surface: v0.11.1
LiveView: v0.19.0
Elixir: v1.14

@tiagoefmoraes
Copy link
Member

@clsource Thanks for the report, mix surface.init --catalogue generates if Mix.env() == :dev do at the module level (compile time) exactly as your suggested fix.

Did you run into any errors trying to run the original code? Or changed the Router somehow? Can you share more details to reproduce the error?

@msaraiva msaraiva closed this as completed Feb 6, 2024
@clsource
Copy link
Author

clsource commented Feb 6, 2024

Thanks. Yes was just a misunderstanding :)
Seems everything is fine .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants