Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: split the handling of / and /api/ of tman designer #469

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,7 @@
"program": "${workspaceFolder}/core/src/ten_manager/target/x86_64-unknown-linux-gnu/debug/tman",
"cwd": "${workspaceFolder}/core/src/ten_manager/target/x86_64-unknown-linux-gnu/debug/",
"args": [
"--verbose",
"designer",
"--base-dir=/home/wei/MyData/MyProject/ten_framework_internal_base/ten_framework/out/linux/x64/tests/ten_runtime/integration/python/aio_http_server_python/aio_http_server_python_app/",
],
"preRunCommands": [
"script import pathlib;import subprocess;import lldb;rustc_sysroot = subprocess.getoutput(\"rustc --print sysroot\");rustlib_etc = pathlib.Path(rustc_sysroot) / \"lib\" / \"rustlib\" / \"etc\";lldb.debugger.HandleCommand(f'command script import \"{rustlib_etc / \"lldb_lookup.py\"}\"');lldb.debugger.HandleCommand(f'command source -s 0 \"{rustlib_etc / \"lldb_commands\"}\"')"
Expand Down
34 changes: 11 additions & 23 deletions core/src/ten_manager/src/cmd/cmd_designer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use std::{
};

use actix_cors::Cors;
use actix_files::Files;
use actix_web::{http::header, web, App, HttpServer};
use anyhow::{Ok, Result};
use clap::{value_parser, Arg, ArgMatches, Command};
Expand All @@ -19,12 +18,12 @@ use console::Emoji;

use crate::{
config::TmanConfig,
designer::{configure_routes, frontend::get_frontend_asset, DesignerState},
designer::{configure_routes, DesignerState},
log::tman_verbose_println,
utils::{check_is_app_folder, get_cwd},
};

#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct DesignerCommand {
pub ip_address: String,
pub port: u16,
Expand Down Expand Up @@ -106,10 +105,10 @@ pub async fn execute_cmd(
tman_verbose_println!(tman_config, "{:?}", command_data);
tman_verbose_println!(tman_config, "{:?}", tman_config);

let base_dir = match command_data.base_dir {
let base_dir = match &command_data.base_dir {
Some(base_dir) => {
println!("Base directory: {}", base_dir);
base_dir
base_dir.clone()
}
None => {
let cwd = get_cwd()?.to_str().unwrap_or_default().to_string();
Expand All @@ -120,7 +119,7 @@ pub async fn execute_cmd(
&cwd
);

cwd
cwd.clone()
}
};

Expand All @@ -144,6 +143,8 @@ pub async fn execute_cmd(
tman_config: TmanConfig::default(),
}));

let command_data_cloned = command_data.clone();

let server = HttpServer::new(move || {
let state = web::Data::new(state.clone());

Expand All @@ -154,25 +155,12 @@ pub async fn execute_cmd(
.allowed_header(header::CONTENT_TYPE)
.max_age(3600);

let mut app = App::new()
App::new()
.app_data(state.clone())
.wrap(cors)
.configure(|cfg| configure_routes(cfg, state.clone()));

if let Some(external_frontend_asset_path) =
&command_data.external_frontend_asset_path
{
let static_files = Files::new("/", external_frontend_asset_path)
.index_file("index.html")
.use_last_modified(true)
.use_etag(true);

app = app.service(static_files);
} else {
app = app.default_service(web::route().to(get_frontend_asset));
}

app
.configure(|cfg| {
configure_routes(cfg, &command_data_cloned, state.clone())
})
});

let bind_address =
Expand Down
142 changes: 77 additions & 65 deletions core/src/ten_manager/src/designer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ mod version;

use std::sync::{Arc, RwLock};

use actix_files::Files;
use actix_web::web;

use frontend::get_frontend_asset;
use ten_rust::pkg_info::PkgInfo;
use terminal::ws_terminal;

use super::config::TmanConfig;
use crate::cmd::cmd_designer::DesignerCommand;
use terminal::ws_terminal;
use version::get_version;

pub struct DesignerState {
Expand All @@ -39,70 +42,79 @@ pub struct DesignerState {

pub fn configure_routes(
cfg: &mut web::ServiceConfig,
command_data: &DesignerCommand,
state: web::Data<Arc<RwLock<DesignerState>>>,
) {
cfg.app_data(state.clone())
.route("/api/designer/v1/version", web::get().to(get_version))
.route(
"/api/designer/v1/addons/extensions",
web::get().to(addons::extensions::get_extension_addons),
)
.route(
"/api/designer/v1/addons/extensions/{name}",
web::get().to(addons::extensions::get_extension_addon_by_name),
)
.route(
"/api/designer/v1/packages/reload",
web::post().to(packages::reload::clear_and_reload_pkgs),
)
.route("/api/designer/v1/graphs", web::get().to(graphs::get_graphs))
.route(
"/api/designer/v1/graphs/{graph_name}/nodes",
web::get().to(graphs::nodes::get_graph_nodes),
)
.route(
"/api/designer/v1/graphs/{graph_name}/connections",
web::get().to(graphs::connections::get_graph_connections),
)
.route(
"/api/designer/v1/graphs/{graph_name}",
web::put().to(graphs::update::update_graph),
)
.route(
"/api/designer/v1/manifest",
web::put().to(manifest::dump::dump_manifest),
)
.route(
"/api/designer/v1/manifest/check",
web::get().to(manifest::check::check_manifest),
)
.route(
"/api/designer/v1/property",
web::put().to(property::dump::dump_property),
)
.route(
"/api/designer/v1/property/check",
web::get().to(property::check::check_property),
)
.route(
"/api/designer/v1/messages/compatible",
web::post().to(messages::compatible::get_compatible_messages),
)
.route(
"/api/designer/v1/file-content/{path}",
web::get().to(file_content::get_file_content),
)
.route(
"/api/designer/v1/file-content/{path}",
web::put().to(file_content::save_file_content),
)
.route(
"/api/designer/v1/base-dir",
web::put().to(base_dir::set_base_dir),
)
.route(
"/api/designer/v1/dir-list/{path}",
web::get().to(dir_list::list_dir),
)
.route("/ws/terminal", web::get().to(ws_terminal));
cfg.service(
web::scope("/api/designer/v1")
.app_data(state.clone())
.route("/version", web::get().to(get_version))
.route(
"/addons/extensions",
web::get().to(addons::extensions::get_extension_addons),
)
.route(
"/addons/extensions/{name}",
web::get().to(addons::extensions::get_extension_addon_by_name),
)
.route(
"/packages/reload",
web::post().to(packages::reload::clear_and_reload_pkgs),
)
.route("/graphs", web::get().to(graphs::get_graphs))
.route(
"/graphs/{graph_name}/nodes",
web::get().to(graphs::nodes::get_graph_nodes),
)
.route(
"/graphs/{graph_name}/connections",
web::get().to(graphs::connections::get_graph_connections),
)
.route(
"/graphs/{graph_name}",
web::put().to(graphs::update::update_graph),
)
.route("/manifest", web::put().to(manifest::dump::dump_manifest))
.route(
"/manifest/check",
web::get().to(manifest::check::check_manifest),
)
.route("/property", web::put().to(property::dump::dump_property))
.route(
"/property/check",
web::get().to(property::check::check_property),
)
.route(
"/messages/compatible",
web::post().to(messages::compatible::get_compatible_messages),
)
.route(
"/file-content/{path}",
web::get().to(file_content::get_file_content),
)
.route(
"/file-content/{path}",
web::put().to(file_content::save_file_content),
)
.route("/base-dir", web::put().to(base_dir::set_base_dir))
.route("/dir-list/{path}", web::get().to(dir_list::list_dir))
.route("/ws/terminal", web::get().to(ws_terminal)),
);

if let Some(external_frontend_asset_path) =
&command_data.external_frontend_asset_path
{
cfg.service(
Files::new("/", external_frontend_asset_path)
.index_file("index.html")
.use_last_modified(true)
.use_etag(true),
);
} else {
cfg.service(
web::scope("/")
.app_data(state.clone())
.default_service(web::route().to(get_frontend_asset)),
);
}
}
Loading