pub struct NodeJsProc { /* private fields */ }
Implementations§
Source§impl NodeJsProc
impl NodeJsProc
Sourcepub fn start(server_path: String, server_url: &Url) -> Result<Self, NodeJsError>
pub fn start(server_path: String, server_url: &Url) -> Result<Self, NodeJsError>
Starts a Node.js child process that runs an Inertia ssr file.
§Arguments
server_path
- The path to thessr.js
file. E.g. “dist/server/ssr.js”.server_url
- The url where the server is running.
§Errors
Returns an NodeJsError
if it fails to start the process, e.g. if the machine do not have
node installed.
§Return
Returns an NodeJsProc
instance. Note that you should call the NodeJsProc::kill(self)
method before the application fully shuts down, or else the Node.js process will keep alive.
§Example
use inertia_rust::node_process::{NodeJsError, NodeJsProc};
use std::str::FromStr;
async fn server() {
let local_url = match reqwest::Url::from_str("localhost:15000") {
Ok(url) => url,
Err(err) => panic!("Failed to parse url: {}", err),
};
let node = NodeJsProc::start("dist/server/ssr.js".into(), &local_url);
if node.is_err() {
let err: NodeJsError = node.unwrap_err();
panic!("Failed to start node server: {}", err);
}
let node = node.unwrap();
// runs the server asynchronously,blocking the function on .await
// when the server stops running, don't forget to:
let _ = node.kill();
}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for NodeJsProc
impl RefUnwindSafe for NodeJsProc
impl Send for NodeJsProc
impl Sync for NodeJsProc
impl Unpin for NodeJsProc
impl UnwindSafe for NodeJsProc
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more