base cors, frontend build script, vite static names for css and js
This commit is contained in:
parent
a95948fc1b
commit
778ea677a8
65
Cargo.lock
generated
65
Cargo.lock
generated
@ -200,9 +200,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.15.3"
|
||||
version = "3.15.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ea184aa71bb362a1157c896979544cc23974e08fd265f29ea96b59f0b4a555b"
|
||||
checksum = "7ff69b9dd49fd426c69a0db9fc04dd934cdb6645ff000864d98f7e2af8830eaa"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
@ -218,9 +218,9 @@ checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.89"
|
||||
version = "1.0.90"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a0ba8f7aaa012f30d5b2861462f6708eccd49c3c39863fe083a308035f63d723"
|
||||
checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
@ -406,12 +406,14 @@ dependencies = [
|
||||
"diesel",
|
||||
"diesel_migrations",
|
||||
"dotenvy",
|
||||
"frontend",
|
||||
"jsonwebtoken",
|
||||
"rand_core",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"time",
|
||||
"tokio",
|
||||
"tower-http",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
"uuid",
|
||||
@ -438,6 +440,13 @@ dependencies = [
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "frontend"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"npm_rs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-channel"
|
||||
version = "0.3.30"
|
||||
@ -560,12 +569,12 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "http-body-util"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41cb79eb393015dadd30fc252023adb0b2400a0caee0fa2a077e6e21a551e840"
|
||||
checksum = "0475f8b2ac86659c21b64320d5d653f9efe42acd2a4e560073ec61a155a34f1d"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"futures-util",
|
||||
"futures-core",
|
||||
"http",
|
||||
"http-body",
|
||||
"pin-project-lite",
|
||||
@ -768,6 +777,15 @@ dependencies = [
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "npm_rs"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1454347ca3c562570eff8af4a09445783dc4b7ccd00853390a7f88f76037b55"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nu-ansi-term"
|
||||
version = "0.46.0"
|
||||
@ -920,9 +938,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.78"
|
||||
version = "1.0.79"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae"
|
||||
checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
@ -1055,9 +1073,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde_path_to_error"
|
||||
version = "0.1.15"
|
||||
version = "0.1.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ebd154a240de39fdebcf5775d2675c204d7c13cf39a4c697be6493c8e734337c"
|
||||
checksum = "af99884400da37c88f5e9146b7f1fd0fbcae8f6eec4e9da38b67d05486f814a6"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"serde",
|
||||
@ -1161,18 +1179,18 @@ checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160"
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.57"
|
||||
version = "1.0.58"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e45bcbe8ed29775f228095caf2cd67af7a4ccf756ebff23a306bf3e8b47b24b"
|
||||
checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.57"
|
||||
version = "1.0.58"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81"
|
||||
checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -1312,6 +1330,23 @@ dependencies = [
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tower-http"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e9cd434a998747dd2c4276bc96ee2e0c7a2eadf3cae88e52be55a05fa9053f5"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bytes",
|
||||
"http",
|
||||
"http-body",
|
||||
"http-body-util",
|
||||
"pin-project-lite",
|
||||
"tower-layer",
|
||||
"tower-service",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tower-layer"
|
||||
version = "0.3.2"
|
||||
|
@ -5,7 +5,7 @@ edition = "2021"
|
||||
authors = ["L-Nafaryus <l.nafaryus@elnafo.ru"]
|
||||
|
||||
[dependencies]
|
||||
axum = "0.7.4"
|
||||
axum = { version = "0.7.4", features = [] }
|
||||
tokio = { version = "1.36.0", default-features = false, features = [
|
||||
"macros",
|
||||
"fs",
|
||||
@ -31,3 +31,9 @@ rand_core = { version = "0.6.4", features = ["std"] }
|
||||
chrono = { version = "0.4.35", features = ["serde"] }
|
||||
jsonwebtoken = "9.2.0"
|
||||
axum-extra = { version = "0.9.2", features = ["cookie"] }
|
||||
tower-http = { version = "0.5.2", features = ["trace", "cors"] }
|
||||
frontend = { version = "0.1.0", path = "crates/frontend" }
|
||||
|
||||
[workspace]
|
||||
members = ["crates/frontend"]
|
||||
resolver = "2"
|
||||
|
7
crates/frontend/Cargo.toml
Normal file
7
crates/frontend/Cargo.toml
Normal file
@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "frontend"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[build-dependencies]
|
||||
npm_rs = "1.0.0"
|
11
crates/frontend/build.rs
Normal file
11
crates/frontend/build.rs
Normal file
@ -0,0 +1,11 @@
|
||||
use npm_rs::*;
|
||||
|
||||
fn main() {
|
||||
let exit_status = NpmEnv::default()
|
||||
.with_node_env(&NodeEnv::from_cargo_profile().unwrap_or_default())
|
||||
.with_env("FOO", "bar")
|
||||
.init_env()
|
||||
.install(None)
|
||||
.run("build")
|
||||
.exec();
|
||||
}
|
0
crates/frontend/src/lib.rs
Normal file
0
crates/frontend/src/lib.rs
Normal file
@ -12,15 +12,15 @@ export default defineConfig({
|
||||
vue(),
|
||||
vueJsx(),
|
||||
],
|
||||
/*root: './src',
|
||||
//root: './src',
|
||||
build: {
|
||||
outDir: "dist",
|
||||
rollupOptions: {
|
||||
input: {
|
||||
app: './src/index.html'
|
||||
output: {
|
||||
entryFileNames: 'assets/[name].js',
|
||||
assetFileNames: 'assets/[name].css'
|
||||
}
|
||||
}
|
||||
},*/
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': fileURLToPath(new URL('./src', import.meta.url))
|
||||
|
@ -64,6 +64,7 @@
|
||||
pkgs.diesel-cli
|
||||
pkgs.cargo-watch
|
||||
pkgs.mold-wrapped
|
||||
pkgs.nodejs
|
||||
];
|
||||
|
||||
shellHook = ''
|
||||
|
32
src/main.rs
32
src/main.rs
@ -6,7 +6,10 @@ pub mod state;
|
||||
|
||||
use axum::{
|
||||
extract::State,
|
||||
http::StatusCode,
|
||||
http::{
|
||||
header::{ACCEPT, AUTHORIZATION, ORIGIN},
|
||||
HeaderValue, Method, StatusCode,
|
||||
},
|
||||
middleware,
|
||||
response::Json,
|
||||
routing::{get, post},
|
||||
@ -16,6 +19,11 @@ use diesel::RunQueryDsl;
|
||||
use std::net::SocketAddr;
|
||||
use std::sync::Arc;
|
||||
use std::{env, net::Ipv4Addr};
|
||||
use tower_http::{
|
||||
cors::{Any, CorsLayer},
|
||||
trace::{self, TraceLayer},
|
||||
};
|
||||
use tracing::Level;
|
||||
|
||||
use crate::config::Config;
|
||||
use crate::db::{create_user, models::User};
|
||||
@ -24,7 +32,11 @@ use crate::state::AppState;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
init_tracing();
|
||||
//init_tracing();
|
||||
tracing_subscriber::fmt()
|
||||
.with_target(false)
|
||||
.compact()
|
||||
.init();
|
||||
|
||||
let config = Config::new();
|
||||
let database_url = format!(
|
||||
@ -51,11 +63,18 @@ async fn main() {
|
||||
|
||||
let lister = tokio::net::TcpListener::bind(&address).await.unwrap();
|
||||
|
||||
let cors = CorsLayer::new()
|
||||
.allow_methods([Method::GET, Method::POST])
|
||||
.allow_headers(Any) //vec![ORIGIN, AUTHORIZATION, ACCEPT])
|
||||
.allow_origin(Any);
|
||||
//.allow_credentials(true); //"http://localhost:5173".parse::<HeaderValue>().unwrap());
|
||||
|
||||
let app = Router::new()
|
||||
.route("/api/v1/healthcheck", get(api::v1::healthcheck))
|
||||
.route("/api/v1/users", get(users))
|
||||
.route("/api/v1/register_user", post(api::v1::register_user))
|
||||
.route("/api/v1/login_user", post(api::v1::login_user))
|
||||
.layer(cors)
|
||||
.route("/api/v1/healthcheck", get(api::v1::healthcheck))
|
||||
.route("/api/v1/users", get(users))
|
||||
.route("/api/v1/logout_user", get(api::v1::logout_user))
|
||||
.route(
|
||||
"/api/v1/me",
|
||||
@ -64,6 +83,11 @@ async fn main() {
|
||||
api::v1::jwt_auth,
|
||||
)),
|
||||
)
|
||||
.layer(
|
||||
TraceLayer::new_for_http()
|
||||
.make_span_with(trace::DefaultMakeSpan::new().level(Level::INFO))
|
||||
.on_response(trace::DefaultOnResponse::new().level(Level::INFO)),
|
||||
)
|
||||
.with_state(state);
|
||||
|
||||
println!("listening on http://{}", address);
|
||||
|
Loading…
Reference in New Issue
Block a user