Comments (7)
@sethlopezme You can already do this via the [global]
table. Check out the configuration API Docs for more details.
from rocket.
I'm leaning towards adding an environment variable. If I do go that route, I'm strongly in favor of using a ROCKET_
namespaced variable. I want to avoid accidental collisions, where a Rocket configuration parameter is accidentally set because some common environment variable was set for a different application.
How big is the impact from having the environment variable not be named PORT
? I imagine it would be a simple change to add ROCKET_PORT=$PORT
, and there's something nice about the self documenting nature of that line.
from rocket.
I've considered being able to pass the default configuration options via command line arguments (--port 312
) or environment variables (ROCKET_PORT=312
), or both, with some definition of precedence. Either of these would let you start rocket with a different port. The former can lead to confusion when an application has its own command line arguments, and so I prefer it less. I believe the latter would work for your use case, is that right?
An alternative, more radical solution is to allow any parameter to be set via any environment variable by specifying the variable in the Rocket.toml
file. Something like this:
[dev]
port = $PORT
Rocket would recognize the $
and require that the PORT
environment variable is set when parsing the config and use the variable's value (which must also parse) as the value of the parameter. But this seems very specialized. Kinda neat though.
from rocket.
We've used all these options in our projects and I'd say the environment variables are for me the best possible way of giving configuration for a running application. This way the deployment configuration handles the environment the application uses, including the secret keys.
Right now I don't really see the reasoning behind the specific configuration files.
The last solution you listed is actually the same Scala uses in its application.conf
. And if you go with the environment variables, please use the standard PORT
so there's no need for specific deployment configuration when deploying to Mesos.
from rocket.
The ability to set any parameter in Rocket.toml
via any environment variable is interesting. This would make it easier to build an application using the Twelve Factor App methodology. I think if this were to happen, there should be a way to define a "default" configuration, and then specify other options depending on the environment. Something like this?
# maybe omit "[default]"?
[default]
address = $APP_HOST
port = $APP_PORT
log = $APP_LOG_LEVEL
session_key = $APP_SESSION_KEY
[dev]
hi = "Hello!"
is_extra = true
This would be similar to having a .env
file with a little extra configurability. What are your thoughts?
from rocket.
Slating the ROCKET_{PARAM}
configuration method for 0.2.
from rocket.
This has been implemented and will ship in 0.2. From the docs:
+//! ## Environment Variables
+//!
+//! All configuration parameters, including extras, can be overridden through
+//! environment variables. To override the configuration parameter `param`, use
+//! an environment variable named `ROCKET_PARAM`. For instance, to override the
+//! "port" configuration parameter, you can run your application with:
+//!
+//! ```sh
+//! ROCKET_PORT=3721 ./your_application
+//! ```
+//!
+//! Environment variables take precedence over all other configuration methods:
+//! if the variable is set, it will be used as the value for the parameter.
+//!
from rocket.
Related Issues (20)
- Rocket sometimes resets connection instead of responding with 413 error response HOT 2
- MiniJinja can't be used for templates HOT 1
- Routing by hostname HOT 10
- New release of rocket_dyn_templates HOT 3
- Redirector issue in TLS example HOT 5
- Deployment Docs - Static Files HOT 1
- FromForm Option<Result> with custom type HOT 4
- Possible error in the Json guard HOT 3
- Allow Generics in route functions HOT 1
- Caching a background image with the `Cache-Control` header HOT 2
- sslmode=required not working for rocket_db_pool with feature diesel_postgres HOT 1
- Fairing returns incorrect Content-Length for status 204 HOT 7
- No way to turn off coloured log output HOT 2
- Implement derive FromParam for enum HOT 1
- Websockets (and any other connection upgrade) does not support local testing.
- `rocket_http` doesn't bulid/test on `rust` `1.80.0` HOT 1
- Expose the `tracing` layer construction to allow you to add other e.g. tracing_subscribers HOT 2
- Implement `PartialEq` for `http::Status` with derive macro HOT 4
- SQLx, Diesel, etc RUSTSEC tracking issue. HOT 2
- Request params fetch by name HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rocket.