socktop-webterm/src/server.rs

48 lines
1.1 KiB
Rust
Raw Normal View History

2019-07-02 02:33:49 +00:00
#[macro_use]
extern crate lazy_static;
2019-03-29 13:48:31 +00:00
use actix_web::{App, HttpServer};
2019-07-02 02:33:49 +00:00
use structopt::StructOpt;
2019-03-29 13:48:31 +00:00
use webterm::WebTermExt;
2019-03-29 15:32:35 +00:00
use std::process::Command;
2019-07-02 02:33:49 +00:00
#[derive(StructOpt, Debug)]
#[structopt(name = "webterm-server")]
struct Opt {
/// The port to listen on
#[structopt(short, long, default_value = "8080")]
port: u16,
/// The host or IP to listen on
#[structopt(short, long, default_value = "localhost")]
host: String,
/// The command to execute
#[structopt(short, long, default_value = "/bin/sh")]
command: String,
}
lazy_static! {
static ref OPT: Opt = Opt::from_args();
}
2019-03-29 13:48:31 +00:00
fn main() {
pretty_env_logger::init();
HttpServer::new(|| {
2019-03-29 13:48:31 +00:00
App::new()
.service(actix_files::Files::new("/static", "./node_modules"))
2019-03-29 15:32:35 +00:00
.webterm_socket("/websocket", |_req| {
2019-07-02 02:33:49 +00:00
let mut cmd = Command::new(OPT.command.clone());
2019-03-29 15:32:35 +00:00
cmd.env("TERM", "xterm");
cmd
})
.webterm_ui("/", "/websocket", "/static")
2019-03-29 13:48:31 +00:00
})
2019-07-02 02:33:49 +00:00
.bind(format!("{}:{}", OPT.host, OPT.port))
2019-03-29 13:48:31 +00:00
.unwrap()
.run()
.unwrap();
2019-03-29 13:48:31 +00:00
}