diff --git a/Cargo.lock b/Cargo.lock index db748d2..3eed9b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -46,6 +46,8 @@ dependencies = [ "axum", "serde", "tokio", + "tower", + "tower-http", "tracing", ] diff --git a/amqp_dashboard/Cargo.toml b/amqp_dashboard/Cargo.toml index f5a37b5..a5989c2 100644 --- a/amqp_dashboard/Cargo.toml +++ b/amqp_dashboard/Cargo.toml @@ -10,4 +10,6 @@ amqp_core = { path = "../amqp_core" } axum = "0.4.5" serde = { version = "1.0.136", features = ["derive"] } tokio = { version = "1.17.0", features = ["full"] } +tower = "0.4.12" +tower-http = { version = "0.2.3", features = ["cors"] } tracing = "0.1.31" diff --git a/amqp_dashboard/frontend/README.md b/amqp_dashboard/frontend/README.md index b58e0af..cbcc2fe 100644 --- a/amqp_dashboard/frontend/README.md +++ b/amqp_dashboard/frontend/README.md @@ -1,46 +1 @@ -# Getting Started with Create React App - -This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). - -## Available Scripts - -In the project directory, you can run: - -### `yarn start` - -Runs the app in the development mode.\ -Open [http://localhost:3000](http://localhost:3000) to view it in the browser. - -The page will reload if you make edits.\ -You will also see any lint errors in the console. - -### `yarn test` - -Launches the test runner in the interactive watch mode.\ -See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. - -### `yarn build` - -Builds the app for production to the `build` folder.\ -It correctly bundles React in production mode and optimizes the build for the best performance. - -The build is minified and the filenames include the hashes.\ -Your app is ready to be deployed! - -See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. - -### `yarn eject` - -**Note: this is a one-way operation. Once you `eject`, you can’t go back!** - -If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. - -Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. - -You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. - -## Learn More - -You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). - -To learn React, check out the [React documentation](https://reactjs.org/). +# Dashboard frontend for the AMQP broker diff --git a/amqp_dashboard/frontend/package.json b/amqp_dashboard/frontend/package.json index 2e49427..8b5dff3 100644 --- a/amqp_dashboard/frontend/package.json +++ b/amqp_dashboard/frontend/package.json @@ -2,6 +2,12 @@ "name": "frontend", "version": "0.1.0", "private": true, + "scripts": { + "start": "react-scripts start", + "build": "react-scripts build", + "test": "react-scripts test", + "eject": "react-scripts eject" + }, "dependencies": { "@testing-library/jest-dom": "^5.14.1", "@testing-library/react": "^12.0.0", @@ -19,12 +25,6 @@ "devDependencies": { "prettier": "^2.5.1" }, - "scripts": { - "start": "react-scripts start", - "build": "react-scripts build", - "test": "react-scripts test", - "eject": "react-scripts eject" - }, "eslintConfig": { "extends": [ "react-app", diff --git a/amqp_dashboard/src/lib.rs b/amqp_dashboard/src/lib.rs index fbc3785..e067b62 100644 --- a/amqp_dashboard/src/lib.rs +++ b/amqp_dashboard/src/lib.rs @@ -3,11 +3,13 @@ use amqp_core::GlobalData; use axum::{ body::{boxed, Full}, + http::Method, response::{Html, IntoResponse, Response}, routing::get, Json, Router, }; use serde::Serialize; +use tower_http::cors::{Any, CorsLayer}; use tracing::info; const INDEX_HTML: &str = include_str!("../assets/index.html"); @@ -15,13 +17,17 @@ const SCRIPT_JS: &str = include_str!("../assets/script.js"); const STYLE_CSS: &str = include_str!("../assets/style.css"); pub async fn dashboard(global_data: GlobalData) { + let cors = CorsLayer::new() + .allow_methods(vec![Method::GET]) + .allow_origin(Any); + let app = Router::new() .route("/", get(get_index_html)) .route("/script.js", get(get_script_js)) .route("/style.css", get(get_style_css)) - .route("/api/data", get(move || get_data(global_data))); + .route("/api/data", get(move || get_data(global_data)).layer(cors)); - let socket_addr = "0.0.0.0:3000".parse().unwrap(); + let socket_addr = "0.0.0.0:8080".parse().unwrap(); info!(%socket_addr, "Starting up dashboard on address"); @@ -57,6 +63,7 @@ struct Data { } #[derive(Serialize)] +#[serde(rename_all = "camelCase")] struct Connection { id: String, peer_addr: String, diff --git a/test-js/src/open-channel.js b/test-js/src/open-channel.js index 0e636ec..2746cf8 100644 --- a/test-js/src/open-channel.js +++ b/test-js/src/open-channel.js @@ -6,7 +6,7 @@ const channel = await connection.createChannel(); console.log('Successfully opened channel'); -await channel.close(); -await connection.close(); - +//await channel.close(); +//await connection.close(); +// console.log('Successfully shut down connection');