1
0
mirror of https://github.com/actix/examples synced 2025-02-25 10:32:49 +01:00

Merge pull request #99 from krircc/master

update actix-web-cors
This commit is contained in:
Nikolay Kim 2019-03-29 18:54:51 -07:00 committed by GitHub
commit 26f7c40d5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 54 additions and 7472 deletions

View File

@ -10,6 +10,6 @@ $ cargo run
```bash ```bash
$ cd web-cors/frontend $ cd web-cors/frontend
$ npm install $ npm install
$ npm run dev $ npm run serve
``` ```
then open browser 'http://localhost:1234/' then open browser 'http://localhost:8080'

View File

@ -15,7 +15,7 @@ fn main() -> std::io::Result<()> {
App::new() App::new()
.wrap( .wrap(
Cors::new() Cors::new()
.allowed_origin("http://localhost:1234") .allowed_origin("http://localhost:8080")
.allowed_methods(vec!["GET", "POST"]) .allowed_methods(vec!["GET", "POST"])
.allowed_headers(vec![header::AUTHORIZATION, header::ACCEPT]) .allowed_headers(vec![header::AUTHORIZATION, header::ACCEPT])
.allowed_header(header::CONTENT_TYPE) .allowed_header(header::CONTENT_TYPE)

View File

@ -1,3 +0,0 @@
{
"presets": ["env"]
}

View File

@ -5,6 +5,7 @@ node_modules/
npm-debug.log* npm-debug.log*
yarn-debug.log* yarn-debug.log*
yarn-error.log* yarn-error.log*
package-lock.json
# Editor directories and files # Editor directories and files
.idea .idea

View File

@ -6,8 +6,6 @@
<title>webapp</title> <title>webapp</title>
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>
<script src="./src/main.js"></script>
</body> </body>
</html>
</html>

File diff suppressed because it is too large Load Diff

View File

@ -1,22 +1,16 @@
{ {
"name": "actix-web-cors", "name": "frontend-vue",
"version": "0.1.0", "version": "0.1.0",
"description": "webapp", "description": "webapp",
"main": "main.js",
"scripts": { "scripts": {
"dev": "rm -rf dist/ && NODE_ENV=development parcel index.html", "serve": "vue-cli-service serve",
"build": "NODE_ENV=production parcel build index.html", "build": "vue-cli-service build"
"test": "echo \"Error: no test specified\" && exit 1"
}, },
"license": "ISC",
"dependencies": { "dependencies": {
"vue": "^2.5.13", "vue": "2.6.10"
"vue-router": "^3.0.1",
"axios": "^0.17.1"
}, },
"devDependencies": { "devDependencies": {
"babel-preset-env": "^1.6.1", "@vue/cli-service": "^3.0.0",
"parcel-bundler": "^1.4.1", "vue-template-compiler": "^2.5.21"
"parcel-plugin-vue": "^1.5.0"
} }
} }

View File

@ -22,45 +22,50 @@
</template> </template>
<script> <script>
import axios from 'axios'
export default { export default {
name: 'app', name: 'app',
data () { data () {
return { return {
Username: '', Username: '',
Email: '', Email: '',
Password: '', Password: '',
ConfirmPassword: '', ConfirmPassword: '',
email: '', email: '',
username: '', username: '',
password: '' password: ''
} }
}, },
methods: { methods: {
signup () { signup () {
var username = this.Username let username = this.Username
var email = this.Email let email = this.Email
var password = this.Password let password = this.Password
var confirm_password = this.ConfirmPassword let confirm_password = this.ConfirmPassword
console.log(email) let data = {
axios.post('http://localhost:8000/user/info', { username: username,
username: username, email: email,
email: email, password: password,
password: password, confirm_password: confirm_password
confirm_password: confirm_password }
}) fetch('http://localhost:8000/user/info', {
.then(response => { body: JSON.stringify(data),
console.log(response.data) headers: {
this.email = response.data.email 'content-type': 'application/json'
this.username = response.data.username },
this.password = response.data.password method: 'POST',
}) }).then(response => response.json())
.catch(e => { .then(json => {
console.log(e) console.log(json)
}) this.email = json.email
} this.username = json.username
} this.password = json.password
})
.catch((e) => {
console.log(e)
})
}
}
} }
</script> </script>
@ -95,7 +100,6 @@ input[type="password"] {
border-radius: 2px; border-radius: 2px;
font-family: 'Roboto', sans-serif; font-family: 'Roboto', sans-serif;
font-weight: bold; font-weight: bold;
text-transform: uppercase;
transition: 0.1s ease; transition: 0.1s ease;
cursor: pointer; cursor: pointer;
} }
@ -142,4 +146,4 @@ cursor: pointer;
padding-top: 100px; padding-top: 100px;
} }
} }
</style> </style>

View File

@ -2,10 +2,5 @@ import Vue from 'vue'
import App from './app' import App from './app'
new Vue({ new Vue({
el: '#app',
render: h => h(App) render: h => h(App)
}) }).$mount('#app')
if (module.hot) {
module.hot.accept();
}