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

The placement of the config.yml file is not really well documented #1583

Open
JJ opened this issue Feb 4, 2021 · 7 comments
Open

The placement of the config.yml file is not really well documented #1583

JJ opened this issue Feb 4, 2021 · 7 comments

Comments

@JJ
Copy link

JJ commented Feb 4, 2021

Or maybe not entirely well specified. In this repo, config.yml is loaded from lib/My, which is if I'm not wrong where the Dancer2 library is used first. However, this will mean that in this program

use v5.14;
use lib qw(lib);

use My::Hitos;
use Dancer2;

dance;

The place where you read the configuration file will depend on where you put the use clause, if My::Hitos also uses Dancer2. It's probably OK if that's what you're looking for, but it should be documented.

@JJ
Copy link
Author

JJ commented Feb 4, 2021

Actually, it does not depend on where you put use Dancer2. It reads from lib/My anyway

@JJ
Copy link
Author

JJ commented Feb 4, 2021

And if you place a (undocumented feature) .dancer file at the top of your thing as indicated in #1580, it reads from that directory!

@JJ
Copy link
Author

JJ commented Feb 4, 2021

It's actually a bit more complicated: When DANCER_CONFIG_VERBOSE is set, it "merges" the config file twice without the .dancer file, three times with that file. Even so, it fails to set the port. Opening a different issue for that.

@veryrusty
Copy link
Member

Every module you use Dancer2; within creates an app (well, instantiates a Dancer2::Core::App object, Dancer2::Core::Runner keeps track of them). Each app get a name, which defaults to the namespace of where it is called.

Your repo has three places there this occurs. My::Hitos, My::Hitos::Config and hitos.psgi (which uses the namespace main). Each instance will load the config file as its app object gets instantiated. See Importing-using-Appname for how to split the code into several files yet combine into a single app.

Config file location will use $ENV{DANCER_CONFDIR} or a heuristic if that is not set. The heuristic looks for (./lib and ./bin) or a .dancer file for up to 10 directories above where the source file is. It then falls back to the directory where the source is if neither of those are found. The heuristic is a bit meh, but the CLI tools for generating a new app put the directories/files needed in the right place for it to work as documented.

Also, your psgi file uses the dance keyword. This uses HTTP::Server::PSGI which is a non-forking single process server. Usually one returns a psgi coderef from their .psgi file (via My::Hitos->to_app), and use other tools like plackup to run the app. You gain all the features plackup offers; app reloading on code changes, and easy switching to other servers like Starman.

@JJ
Copy link
Author

JJ commented Feb 4, 2021

OK, I see what you mean. Let me try that. Maybe once I do I also fix the problems #1584 and #1585

@JJ
Copy link
Author

JJ commented Feb 4, 2021

OK, changed to

use v5.14;
use lib qw(lib);
use My::Hitos;
My::Hitos->to_app;

And it boots up alright. Still no trace of #1584 and #1585 working. It's reading the configuration file just the once:

Merging config file /home/jmerelo/Asignaturas/cloud-computing/p5-hitos/config.yml
/tmp
HTTP::Server::PSGI: Accepting connections at http://0:5000/

but not paying any attention at the port setting either in the config or in the application itself.

@JJ
Copy link
Author

JJ commented Feb 4, 2021

The original issue still stands (kinda). Your comment is not entirely clarified in the documentation.

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

2 participants