refactor: split up bin and lib
This commit is contained in:
parent
6bdfd1118a
commit
e63ad944d7
@ -21,3 +21,11 @@ futures = "0.1.25"
|
||||
|
||||
[patch.crates-io]
|
||||
tokio-pty-process = {path = "vendor/stund/tokio-pty-process"}
|
||||
|
||||
[lib]
|
||||
name = "webterm"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "webterm-server"
|
||||
path = "src/server.rs"
|
||||
@ -42,7 +42,7 @@ extern crate log;
|
||||
extern crate pretty_env_logger;
|
||||
|
||||
use actix::*;
|
||||
use actix_web::{fs::NamedFile, fs::StaticFiles, server, ws, App, HttpRequest, Result};
|
||||
use actix_web::{ws, App};
|
||||
|
||||
use futures::prelude::*;
|
||||
|
||||
@ -137,10 +137,6 @@ impl Websocket {
|
||||
}
|
||||
}
|
||||
|
||||
fn index(_req: &HttpRequest) -> Result<NamedFile> {
|
||||
Ok(NamedFile::open("static/term.html")?)
|
||||
}
|
||||
|
||||
impl StreamHandler<ws::Message, ws::ProtocolError> for Websocket {
|
||||
fn handle(&mut self, msg: ws::Message, ctx: &mut Self::Context) {
|
||||
let cons: &mut Addr<Terminal> = match self.cons {
|
||||
@ -301,7 +297,7 @@ impl Handler<event::TerminadoMessage> for Terminal {
|
||||
ctx.stop();
|
||||
}
|
||||
}
|
||||
event::TerminadoMessage::Resize { cols, rows } => {
|
||||
event::TerminadoMessage::Resize { rows, cols } => {
|
||||
info!("Resize: cols = {}, rows = {}", cols, rows);
|
||||
if let Err(e) = event::Resize::new(pty, cols, rows).wait() {
|
||||
error!("Resize failed: {}", e);
|
||||
@ -326,22 +322,3 @@ impl WebTermExt for App<()> {
|
||||
self.resource(endpoint, |r| r.f(|req| ws::start(req, Websocket::new())))
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
pretty_env_logger::init();
|
||||
|
||||
server::new(|| {
|
||||
App::new()
|
||||
.handler(
|
||||
"/static",
|
||||
StaticFiles::new("node_modules")
|
||||
.unwrap()
|
||||
.show_files_listing(),
|
||||
)
|
||||
.webterm_socket("/websocket")
|
||||
.resource("/", |r| r.f(index))
|
||||
})
|
||||
.bind("127.0.0.1:8080")
|
||||
.unwrap()
|
||||
.run();
|
||||
}
|
||||
29
src/server.rs
Normal file
29
src/server.rs
Normal file
@ -0,0 +1,29 @@
|
||||
extern crate actix;
|
||||
extern crate actix_web;
|
||||
extern crate webterm;
|
||||
|
||||
use actix_web::{fs::NamedFile, fs::StaticFiles, server, App, HttpRequest, Result};
|
||||
use webterm::WebTermExt;
|
||||
|
||||
fn index(_req: &HttpRequest) -> Result<NamedFile> {
|
||||
Ok(NamedFile::open("static/term.html")?)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
pretty_env_logger::init();
|
||||
|
||||
server::new(|| {
|
||||
App::new()
|
||||
.handler(
|
||||
"/static",
|
||||
StaticFiles::new("node_modules")
|
||||
.unwrap()
|
||||
.show_files_listing(),
|
||||
)
|
||||
.webterm_socket("/websocket")
|
||||
.resource("/", |r| r.f(index))
|
||||
})
|
||||
.bind("127.0.0.1:8080")
|
||||
.unwrap()
|
||||
.run();
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user