leafo / lapis

A web framework for Lua and OpenResty written in MoonScript
http://leafo.net/lapis/
MIT License
3.12k stars 247 forks source link

lapis server [env] ignores config.moon #738

Closed katsifolis closed 2 years ago

katsifolis commented 3 years ago

I have this problem with lapis

-- config.moon
import config from require "lapis.config"
config "production", ->
   port 8001
   num_workers 4
   code_cache "on"

when i run lapis server production there is no modification in nginx.conf.compiled whatsoever so the port doesn't change nor the code_cache. However the server runs normally under :8080

Lapis 1.9.0
leafo commented 3 years ago

Do you have anything that might be overriding the environment name, like lapis_environment.lua or the LAPIS_ENVIRONMENT environment variable set?

What does the first line of nginx.conf.compiled say? It should have a line that shows the environment name

katsifolis commented 3 years ago

This doesn't seem to be an environment error because the first line of conf.compiled gets changed if I pass a name other than production.

config.moon


-- config.moon
import config from require "lapis.config"
config "production", ->
port 8001
num_workers 4
code_cache "on"

config "dev", -> port 8081 num_workers 1 code_cache "on"

cat nginx.conf.compiled env LAPIS_ENVIRONMENT=production; worker_processes 4; error_log stderr notice; daemon off; pid logs/nginx.pid;

events { worker_connections 1024; }

http { include mime.types; lua_package_path "./?.lua;;";

server { listen 8080; lua_code_cache off;

location / {
  default_type text/html;
  content_by_lua_block {
    require("lapis").serve("app")
  }
}

location /static/ {
  alias static/;
}

location /favicon.ico {
  alias static/favicon.ico;
}

} }

cat nginx.conf.compiled env LAPIS_ENVIRONMENT=dev; worker_processes 4; error_log stderr notice; daemon off; pid logs/nginx.pid;

events { worker_connections 1024; }

http { include mime.types; lua_package_path "./?.lua;;";

server { listen 8080; lua_code_cache off;

location / {
  default_type text/html;
  content_by_lua_block {
    require("lapis").serve("app")
  }
}

location /static/ {
  alias static/;
}

location /favicon.ico {
  alias static/favicon.ico;
}

} }

leafo commented 3 years ago

Are you sure your port is a variable on the source nginx.conf?

Also did you compile your moon files?

katsifolis commented 3 years ago

Yeah it is ..

worker_processes 4;
error_log stderr notice;
daemon off;
pid logs/nginx.pid;

events {
  worker_connections 1024;
}

http {
  include mime.types;
  lua_package_path "./?.lua;;";

  server {
    listen ${{PORT}};
    lua_code_cache ${{CODE_CACHE}};

    location / {
      default_type text/html;
      content_by_lua_block {
        require("lapis").serve("app")
      }
    }

    location /static/ {
      alias static/;
    }

    location /favicon.ico {
      alias static/favicon.ico;
    }
  }
}

Sure I am running tup..

leafo commented 3 years ago

Can you double check that config.lua exists in the folder where you're running the lapis command, and the contents reflect the correct details

katsifolis commented 3 years ago

Yeap I checked and it looks like this.

local config
config = require("lapis.config").config
config("production", function()
  port(8001)
  num_workers(4)
  code_cache("on")
end)
return config("dev", function()
  port(8081)
  num_workers(1)
  code_cache("off")
end)
leafo commented 3 years ago

does running LAPIS_ENVIRONMENT=production lapis server do what you expect?

katsifolis commented 3 years ago

No it just bypasses it.

leafo commented 3 years ago

Well, I'm probably at the end of helping you debug it. There's something about your environment that is changing how it works, or something you're missing (typo, file you didn't notice, something not compiled, lua code path, etc.). Environment selection is working as expected on our test suite and in all severs I'm using it in.

You might also want to check you're running the latest version of lapis.

You can then try uninstalling it, then removing all traces of lapis from the luarocks install directory to make sure you're getting clean install.

katsifolis commented 3 years ago

Okay thanks a lot for your insight. I will try to reinstall in a fresh environment!