Last active
March 6, 2019 23:55
-
-
Save dmcguire81/f3f459a0a5a570ca1482d596ba36460a to your computer and use it in GitHub Desktop.
Hello world actix-web example with multiple CORS allowed origins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate actix_web; | |
use actix_web::middleware::cors::Cors; | |
use actix_web::{server, App, HttpRequest}; | |
fn index(_req: &HttpRequest) -> &'static str { | |
"Hello world!" | |
} | |
fn main() { | |
server::new(|| { | |
App::new() | |
.middleware( | |
Cors::build() | |
.allowed_origin("http://localhost") | |
.allowed_origin("http://localhost:5200") | |
.finish(), | |
) | |
.resource("/", |r| r.f(index)) | |
}) | |
.bind("127.0.0.1:8088") | |
.unwrap() | |
.run(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
openapi: 3.0.0 | |
info: | |
version: "1.0.0" | |
title: Hello World | |
description: | | |
Demonstratining CORS preflight defect via Swagger UI | |
contact: | |
name: Joylabs Engineering Group | |
email: [email protected] | |
servers: | |
- url: "http://localhost:8088" | |
paths: | |
/: | |
post: | |
summary: print "Hello, World!" | |
requestBody: | |
description: A salution to the server | |
content: | |
application/text: | |
schema: | |
type: string | |
responses: | |
"200": | |
description: Success | |
content: | |
application/text: | |
schema: | |
type: string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment