This commit is contained in:
nora 2022-03-06 14:33:01 +01:00
parent 5befe288e5
commit d7b574cef4
6 changed files with 23 additions and 57 deletions

2
Cargo.lock generated
View file

@ -46,6 +46,8 @@ dependencies = [
"axum", "axum",
"serde", "serde",
"tokio", "tokio",
"tower",
"tower-http",
"tracing", "tracing",
] ]

View file

@ -10,4 +10,6 @@ amqp_core = { path = "../amqp_core" }
axum = "0.4.5" axum = "0.4.5"
serde = { version = "1.0.136", features = ["derive"] } serde = { version = "1.0.136", features = ["derive"] }
tokio = { version = "1.17.0", features = ["full"] } tokio = { version = "1.17.0", features = ["full"] }
tower = "0.4.12"
tower-http = { version = "0.2.3", features = ["cors"] }
tracing = "0.1.31" tracing = "0.1.31"

View file

@ -1,46 +1 @@
# Getting Started with Create React App # Dashboard frontend for the AMQP broker
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 cant go back!**
If you arent 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 youre on your own.
You dont have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldnt feel obligated to use this feature. However we understand that this tool wouldnt be useful if you couldnt 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/).

View file

@ -2,6 +2,12 @@
"name": "frontend", "name": "frontend",
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"dependencies": { "dependencies": {
"@testing-library/jest-dom": "^5.14.1", "@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^12.0.0", "@testing-library/react": "^12.0.0",
@ -19,12 +25,6 @@
"devDependencies": { "devDependencies": {
"prettier": "^2.5.1" "prettier": "^2.5.1"
}, },
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": { "eslintConfig": {
"extends": [ "extends": [
"react-app", "react-app",

View file

@ -3,11 +3,13 @@
use amqp_core::GlobalData; use amqp_core::GlobalData;
use axum::{ use axum::{
body::{boxed, Full}, body::{boxed, Full},
http::Method,
response::{Html, IntoResponse, Response}, response::{Html, IntoResponse, Response},
routing::get, routing::get,
Json, Router, Json, Router,
}; };
use serde::Serialize; use serde::Serialize;
use tower_http::cors::{Any, CorsLayer};
use tracing::info; use tracing::info;
const INDEX_HTML: &str = include_str!("../assets/index.html"); 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"); const STYLE_CSS: &str = include_str!("../assets/style.css");
pub async fn dashboard(global_data: GlobalData) { pub async fn dashboard(global_data: GlobalData) {
let cors = CorsLayer::new()
.allow_methods(vec![Method::GET])
.allow_origin(Any);
let app = Router::new() let app = Router::new()
.route("/", get(get_index_html)) .route("/", get(get_index_html))
.route("/script.js", get(get_script_js)) .route("/script.js", get(get_script_js))
.route("/style.css", get(get_style_css)) .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"); info!(%socket_addr, "Starting up dashboard on address");
@ -57,6 +63,7 @@ struct Data {
} }
#[derive(Serialize)] #[derive(Serialize)]
#[serde(rename_all = "camelCase")]
struct Connection { struct Connection {
id: String, id: String,
peer_addr: String, peer_addr: String,

View file

@ -6,7 +6,7 @@ const channel = await connection.createChannel();
console.log('Successfully opened channel'); console.log('Successfully opened channel');
await channel.close(); //await channel.close();
await connection.close(); //await connection.close();
//
console.log('Successfully shut down connection'); console.log('Successfully shut down connection');