mirror of
https://github.com/deps-rs/deps.rs.git
synced 2024-11-22 10:26:30 +00:00
add dynamic port binding
This commit is contained in:
parent
32ce37636a
commit
084520207b
1 changed files with 9 additions and 3 deletions
12
src/main.rs
12
src/main.rs
|
@ -1,5 +1,6 @@
|
||||||
#![feature(ascii_ctype)]
|
#![feature(ascii_ctype)]
|
||||||
#![feature(conservative_impl_trait)]
|
#![feature(conservative_impl_trait)]
|
||||||
|
#![feature(ip_constructors)]
|
||||||
#![feature(proc_macro)]
|
#![feature(proc_macro)]
|
||||||
|
|
||||||
extern crate futures;
|
extern crate futures;
|
||||||
|
@ -23,7 +24,8 @@ mod interactors;
|
||||||
mod engine;
|
mod engine;
|
||||||
mod server;
|
mod server;
|
||||||
|
|
||||||
use std::net::SocketAddr;
|
use std::env;
|
||||||
|
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
|
||||||
use futures::{Future, Stream};
|
use futures::{Future, Stream};
|
||||||
|
@ -54,8 +56,10 @@ fn main() {
|
||||||
.connector(connector)
|
.connector(connector)
|
||||||
.build(&core.handle());
|
.build(&core.handle());
|
||||||
|
|
||||||
let addr = "0.0.0.0:8080".parse::<SocketAddr>()
|
let port = env::var("PORT").unwrap_or_else(|_| "8080".to_string()).parse()
|
||||||
.expect("failed to parse socket addr");
|
.expect("could not read port");
|
||||||
|
|
||||||
|
let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::unspecified()), port);
|
||||||
|
|
||||||
let http = Http::new();
|
let http = Http::new();
|
||||||
|
|
||||||
|
@ -80,5 +84,7 @@ fn main() {
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
|
|
||||||
|
println!("Server running on port {}", port);
|
||||||
|
|
||||||
core.run(serving).expect("server failed");
|
core.run(serving).expect("server failed");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue