Handle CORS properly

This commit is contained in:
JSH32 2022-09-22 14:35:06 -05:00
parent 3f3c9b1477
commit 5b5d911067
5 changed files with 31 additions and 4 deletions

16
Cargo.lock generated
View File

@ -25,6 +25,21 @@ dependencies = [
"tokio-util",
]
[[package]]
name = "actix-cors"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "684a6ce1562a5fcca49bc9302896c63547eea78a1e405e837e7416affd8b6eb9"
dependencies = [
"actix-utils",
"actix-web",
"derive_more",
"futures-util",
"log",
"once_cell",
"smallvec",
]
[[package]]
name = "actix-files"
version = "0.6.0"
@ -528,6 +543,7 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
name = "backpack"
version = "0.1.0"
dependencies = [
"actix-cors",
"actix-files",
"actix-http",
"actix-multipart",

View File

@ -63,4 +63,5 @@ heck = "0.4.0"
oauth2 = "4.2.3"
reqwest = { version = "0.11.11", features = [ "json" ] }
moka = { version = "0.9.4", features = ["future"] }
url = "2.3.1"
url = "2.3.1"
actix-cors = "0.6"

View File

@ -2,7 +2,7 @@
/* tslint:disable */
import axios from 'axios';
import type { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios';
import * as FormData from 'form-data';
import FormData from 'form-data';
import { ApiError } from './ApiError';
import type { ApiRequestOptions } from './ApiRequestOptions';

View File

@ -4,8 +4,8 @@
"private": true,
"scripts": {
"dev": "NODE_ENV=development dotenv -- next dev",
"build": "NODE_ENV=production next build",
"start": "NODE_ENV=production next start",
"build": "NODE_ENV=production dotenv -- next build",
"start": "NODE_ENV=production dotenv -- next start",
"lint": "next lint",
"generateClient": "find ./client ! -name 'README.md' -type f -exec rm -f {} + && openapi --input http://localhost:3000/api/docs/openapi.json --output ./client --client axios --name BackpackClient"
},

View File

@ -37,6 +37,7 @@ use actix_web::{
App, HttpRequest, HttpResponse, HttpServer,
};
use actix_cors::Cors;
use actix_files::NamedFile;
#[macro_use]
@ -169,6 +170,8 @@ async fn main() -> std::io::Result<()> {
_ => None,
};
let client_url = config.client_url.clone();
log::info!(
"Starting webserver on port {}",
config.port.to_string().yellow()
@ -178,6 +181,13 @@ async fn main() -> std::io::Result<()> {
let base_storage_path = storage_path.clone();
App::new()
.wrap(Logger::default())
.wrap(
Cors::default()
.allowed_origin(&client_url)
.allow_any_header()
.allow_any_method()
.max_age(None),
)
.app_data(database.clone())
.app_data(registration_key_service.clone())
.app_data(user_service.clone())