mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-05 17:58:55 +00:00
storyteller render cors
This commit is contained in:
1 parent
6adb104e58
commit
f3cde45f33
3 files changed
+67
-3
No files matched your search
@@ -2,5 +2,6 @@ pub (crate) mod development_only;
|
||||
pub (crate) mod fakeyou;
|
||||
pub (crate) mod legacy;
|
||||
pub (crate) mod storyteller;
|
||||
pub (crate) mod storyteller_studio;
|
||||
pub (crate) mod storyteller_board;
|
||||
pub (crate) mod storyteller_board;
|
||||
pub (crate) mod storyteller_render;
|
||||
pub (crate) mod storyteller_studio;
|
||||
@@ -0,0 +1,61 @@
|
||||
use actix_cors::Cors;
|
||||
|
||||
use crate::util::netlify_branch_domain_matches::netlify_branch_domain_matches;
|
||||
|
||||
pub fn add_storyteller_render(cors: Cors, _is_production: bool) -> Cors {
|
||||
cors
|
||||
// Hypothetical domains
|
||||
.allowed_origin("https://render.storyteller.ai")
|
||||
// Netlify project
|
||||
.allowed_origin_fn(|origin, _req_head| {
|
||||
netlify_branch_domain_matches(origin, "storyteller-render.netlify.app")
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use reusable_types::server_environment::ServerEnvironment;
|
||||
|
||||
use crate::cors::build_cors_config;
|
||||
use crate::testing::assert_origin_invalid;
|
||||
use crate::testing::assert_origin_ok;
|
||||
|
||||
mod domains {
|
||||
use super::*;
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn board_dot_storyteller() {
|
||||
let production_cors = build_cors_config(ServerEnvironment::Production);
|
||||
assert_origin_ok(&production_cors, "https://render.storyteller.ai").await;
|
||||
}
|
||||
}
|
||||
|
||||
mod netlify {
|
||||
use super::*;
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn netlify_main() {
|
||||
let production_cors = build_cors_config(ServerEnvironment::Production);
|
||||
assert_origin_ok(&production_cors, "https://storyteller-render.netlify.app").await;
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn netlify_branch_deploy() {
|
||||
let production_cors = build_cors_config(ServerEnvironment::Production);
|
||||
assert_origin_ok(&production_cors, "https://test--storyteller-render.netlify.app").await;
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn netlify_deploy_preview() {
|
||||
let production_cors = build_cors_config(ServerEnvironment::Production);
|
||||
assert_origin_ok(&production_cors, "https://deploy-preview-123--storyteller-render.netlify.app").await;
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn invalid_netlify_preview_deploy() {
|
||||
let production_cors = build_cors_config(ServerEnvironment::Production);
|
||||
assert_origin_invalid(&production_cors, "https://storyteller-render--unrelated.netlify.app").await;
|
||||
assert_origin_invalid(&production_cors, "https://deploy-preview-123--unrelated.netlify.app").await;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,11 @@ use reusable_types::server_environment::ServerEnvironment;
|
||||
|
||||
use crate::configs::development_only::add_development_only;
|
||||
use crate::configs::fakeyou::{add_fakeyou, add_fakeyou_dev_proxy};
|
||||
use crate::configs::storyteller_studio::add_storyteller_studio;
|
||||
use crate::configs::legacy::{add_legacy_storyteller_stream, add_legacy_trumped, add_legacy_vocodes, add_power_stream};
|
||||
use crate::configs::storyteller::{add_storyteller, add_storyteller_dev_proxy};
|
||||
use crate::configs::storyteller_board::add_storyteller_board;
|
||||
use crate::configs::storyteller_render::add_storyteller_render;
|
||||
use crate::configs::storyteller_studio::add_storyteller_studio;
|
||||
|
||||
/// Return cors config for FakeYou / Vocodes / OBS / local development
|
||||
pub fn build_cors_config(server_environment: ServerEnvironment) -> Cors {
|
||||
@@ -37,6 +38,7 @@ fn do_build_cors_config(is_production: bool) -> Cors {
|
||||
cors = add_storyteller_dev_proxy(cors, is_production);
|
||||
cors = add_storyteller_studio(cors, is_production);
|
||||
cors = add_storyteller_board(cors, is_production);
|
||||
cors = add_storyteller_render(cors, is_production);
|
||||
|
||||
// Legacy
|
||||
cors = add_legacy_trumped(cors, is_production);
|
||||
|
||||
Reference in new issue
Block a user