1
0
mirror of https://github.com/actix/examples synced 2025-02-17 07:23:29 +01:00

fix vue example ports

closes #624
This commit is contained in:
Rob Ede 2023-07-17 22:26:11 +01:00
parent da976e0415
commit f3cf37bb0d
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
5 changed files with 151 additions and 116 deletions

23
Cargo.lock generated
View File

@ -491,17 +491,6 @@ dependencies = [
"syn 1.0.109",
]
[[package]]
name = "actix-web-cors"
version = "1.0.0"
dependencies = [
"actix-cors",
"actix-web",
"env_logger",
"serde",
"serde_json",
]
[[package]]
name = "actix-web-lab"
version = "0.19.1"
@ -2296,6 +2285,18 @@ version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
[[package]]
name = "cors"
version = "1.0.0"
dependencies = [
"actix-cors",
"actix-web",
"env_logger",
"log",
"serde",
"serde_json",
]
[[package]]
name = "cpufeatures"
version = "0.2.9"

View File

@ -1,5 +1,5 @@
[package]
name = "actix-web-cors"
name = "cors"
version = "1.0.0"
edition = "2021"
@ -8,5 +8,6 @@ actix-web = { workspace = true, features = ["rustls"] }
actix-cors.workspace = true
env_logger.workspace = true
serde = { version = "1.0", features = ["derive"] }
log.workspace = true
serde.workspace = true
serde_json.workspace = true

View File

@ -1,17 +1,21 @@
use std::io;
use actix_cors::Cors;
use actix_web::{http::header, middleware::Logger, App, HttpServer};
mod user;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
async fn main() -> io::Result<()> {
env_logger::init_from_env(env_logger::Env::default().default_filter_or("info"));
log::info!("starting HTTP server at http://localhost:8080");
HttpServer::new(move || {
App::new()
.wrap(
Cors::default()
.allowed_origin("http://localhost:8080")
.allowed_origin("http://localhost:8081")
.allowed_methods(vec!["GET", "POST"])
.allowed_headers(vec![header::AUTHORIZATION, header::ACCEPT])
.allowed_header(header::CONTENT_TYPE)

View File

@ -4,15 +4,42 @@
<div id="title">
<a to="#">SignUp</a>
</div>
<input type="text" name="username" placeholder="Username" v-model="Username" required />
<input type="text" name="email" placeholder="E-mail" v-model="Email" required />
<input type="password" name="password" placeholder="Password" v-model="Password" required/>
<input type="password" name="confirm_password" placeholder="Confirm password" v-model="ConfirmPassword" required/><br/>
<input
type="text"
name="username"
placeholder="Username"
v-model="Username"
required
/>
<input
type="text"
name="email"
placeholder="E-mail"
v-model="Email"
required
/>
<input
type="password"
name="password"
placeholder="Password"
v-model="Password"
required
/>
<input
type="password"
name="confirm_password"
placeholder="Confirm password"
v-model="ConfirmPassword"
required
/><br />
<button id="submit" @click="signup">Sign up</button>
<div id="user-info">
<p>Click Above 'Sign up' Button <br> Then Get Your Signup Info!</p>
<p>
Click Above 'Sign up' Button <br />
Then Get Your Signup Info!
</p>
<p>email : {{ email }}</p>
<p>username : {{ username }}</p>
<p>password : {{ password }}</p>
@ -33,7 +60,7 @@ export default {
email: '',
username: '',
password: ''
password: '',
}
},
methods: {
@ -46,16 +73,17 @@ export default {
username: username,
email: email,
password: password,
confirm_password: confirm_password
confirm_password: confirm_password,
}
fetch('http://localhost:8000/user/info', {
fetch('http://localhost:8080/user/info', {
body: JSON.stringify(data),
headers: {
'content-type': 'application/json'
'content-type': 'application/json',
},
method: 'POST',
}).then(response => response.json())
.then(json => {
})
.then((response) => response.json())
.then((json) => {
console.log(json)
this.email = json.email
this.username = json.username
@ -64,8 +92,8 @@ export default {
.catch((e) => {
console.log(e)
})
}
}
},
},
}
</script>
@ -82,13 +110,13 @@ export default {
background-color: bisque;
text-align: center;
}
input[type="text"],
input[type="password"] {
input[type='text'],
input[type='password'] {
margin: 6px auto auto;
width: 250px;
height: 36px;
border: none;
border-bottom: 1px solid #AAA;
border-bottom: 1px solid #aaa;
font-size: 16px;
}
#submit {
@ -103,7 +131,7 @@ input[type="password"] {
transition: 0.1s ease;
cursor: pointer;
}
input[type="checkbox"] {
input[type='checkbox'] {
margin-top: 11px;
}
dialog {
@ -131,7 +159,8 @@ color: white;
font-weight: bold;
text-align: center;
}
#closeDialog:hover, #closeDialog:focus {
#closeDialog:hover,
#closeDialog:focus {
opacity: 0.92;
cursor: pointer;
}

View File

@ -4,11 +4,11 @@ version = "1.0.0"
edition = "2021"
[dependencies]
actix-web = "4"
chrono = { version = "0.4.26", default-features = false, features = ["std", "clock"] }
derive_more = "0.99.7"
actix-web.workspace = true
chrono.workspace = true
derive_more.workspace = true
dotenv = "0.15"
env_logger = "0.10"
log = "0.4"
env_logger.workspace = true
log.workspace = true
mysql = "24"
serde = { version = "1", features = ["derive"] }
serde.workspace = true