+6
-6
README.md
+6
-6
README.md
···
17
17
[`gleam_http`](https://hexdocs.pm/gleam_http) `Response` as a foundation.
18
18
However, to simplify your development, two middlewares are provided
19
19
out-of-the-box:
20
-
[`wisp_handle`](https://hexdocs.pm/cors_builder/cors_builder.html#wisp_handle)
20
+
[`wisp_middleware`](https://hexdocs.pm/cors_builder/cors_builder.html#wisp_middleware)
21
21
and
22
-
[`mist_handle`](https://hexdocs.pm/cors_builder/cors_builder.html#mist_handle)
22
+
[`mist_middleware`](https://hexdocs.pm/cors_builder/cors_builder.html#mist_middleware)
23
23
to integrate nicely in [`wisp`](https://hexdocs.pm/wisp) and
24
24
[`mist`](https://hexdocs.pm/mist). You should never have to worry about CORS
25
25
again! Use the package, configure your CORS, and everything should work
···
27
27
28
28
## Quickstart
29
29
30
-
You can interchange `wisp_handle` with `mist_handle` if you're using `wisp` or
31
-
`mist`.
30
+
You can interchange `wisp_middleware` with `mist_middleware` if you're using
31
+
`wisp` or `mist`.
32
32
33
33
```gleam
34
34
import cors_builder as cors
···
45
45
}
46
46
47
47
fn handler(req: Request) -> Response {
48
-
use req <- cors.wisp_handle(req, cors())
48
+
use req <- cors.wisp_middleware(req, cors())
49
49
wisp.ok()
50
50
}
51
51
52
52
fn main() {
53
53
handler
54
-
|> wisp.mist_handler(secret_key)
54
+
|> wisp.mist_middlewarer(secret_key)
55
55
|> mist.new()
56
56
|> mist.port(3000)
57
57
|> mist.start_http()
+5
-5
src/cors_builder.gleam
+5
-5
src/cors_builder.gleam
···
23
23
//// }
24
24
////
25
25
//// fn handler(req: Request) -> Response {
26
-
//// use req <- cors.wisp_handle(req, cors())
26
+
//// use req <- cors.wisp_middleware(req, cors())
27
27
//// wisp.ok()
28
28
//// }
29
29
////
···
328
328
/// Set CORS headers on a response. Should be used in your handler.
329
329
/// In case you're using a framework, it probably already implements it.
330
330
/// If you're using mist or wisp, use the corresponding provided middlewares,
331
-
/// ([mist_handle](#mist_handle)) and ([wisp_handle](#wisp_handle)) and do not
331
+
/// ([mist_middleware](#mist_middleware)) and ([wisp_middleware](#wisp_middleware)) and do not
332
332
/// use this "low-level" function.
333
333
pub fn set_cors(res: Response(response), cors: Cors) {
334
334
set_response(res, cors, None)
···
338
338
/// allowed domains. Should be used in your handler.
339
339
/// In case you're using a framework, it probably already implements it.
340
340
/// If you're using mist or wisp, use the corresponding provided middlewares,
341
-
/// ([mist_handle](#mist_handle)) and ([wisp_handle](#wisp_handle)) and do not
341
+
/// ([mist_middleware](#mist_middleware)) and ([wisp_middleware](#wisp_middleware)) and do not
342
342
/// use this "low-level" function.
343
343
pub fn set_cors_multiple_origin(
344
344
res: Response(response),
···
373
373
374
374
/// Intercepts the request for mist and handles CORS directly without worrying
375
375
/// about it. Provide your CORS configuration, and you're good to go!
376
-
pub fn mist_handle(
376
+
pub fn mist_middleware(
377
377
req: Request(mist.Connection),
378
378
cors: Cors,
379
379
handler: fn(Request(mist.Connection)) -> Response(mist.ResponseData),
···
385
385
386
386
/// Intercepts the request for wisp and handles CORS directly without worrying
387
387
/// about it. Provide your CORS configuration and you're good to go!
388
-
pub fn wisp_handle(
388
+
pub fn wisp_middleware(
389
389
req: wisp.Request,
390
390
cors: Cors,
391
391
handler: fn(wisp.Request) -> wisp.Response,
+1
-1
test/servers/full.gleam
+1
-1
test/servers/full.gleam
+1
-1
test/servers/none.gleam
+1
-1
test/servers/none.gleam
···
5
5
import mist.{type Connection, type ResponseData}
6
6
7
7
pub fn run(req: Request(Connection)) -> Response(ResponseData) {
8
-
use _req <- cors.mist_handle(req, cors.new())
8
+
use _req <- cors.mist_middleware(req, cors.new())
9
9
let empty = mist.Bytes(bytes_builder.from_string("OK"))
10
10
response.new(200)
11
11
|> response.set_body(empty)
+1
-1
test/servers/partial.gleam
+1
-1
test/servers/partial.gleam
···
13
13
}
14
14
15
15
pub fn run(req: Request(Connection)) -> Response(ResponseData) {
16
-
use _req <- cors.mist_handle(req, cors())
16
+
use _req <- cors.mist_middleware(req, cors())
17
17
let empty = mist.Bytes(bytes_builder.from_string("OK"))
18
18
response.new(200)
19
19
|> response.set_body(empty)