Description Usage Arguments Value Note See Also Examples
View source: R/utils-middleware.R
Allow Cross-Origin Resource Sharing headers as described in MDN Web Docs. Cross-origin resource sharing is a mechanism that allows restricted resources on a web page to be requested from another domain(origin) outside the domain from which the first resource was served.
1 2 3 4 5 6 7 8 9 10 |
beakr |
|
path |
String representing a path for which to specify a CORS policy.
Default |
methods |
A vector of the request methods to allow. i.e
|
origin |
A vector of the request origin(s) for which resource sharing
is enabled. i.e |
credentials |
A boolean to enable/disable credentialed requests. i.e
|
headers |
A vector of the allowed headers. i.e
|
maxAge |
The max age, in seconds. i.e |
expose |
The headers to expose. i.e |
A Beakr
instance with CORS enabled
You can verify that CORS is enabled by using the Chrome browser and
opening up the Developer Tools. The "Network" tab allows you to inspect
response headers and see where the Cross-Origin
policy is specified.
If you run the example in the console, be sure to
stopServer(bekar)
when you are done.
Request, Response, Error
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | library(beakr)
# Create an new beakr instance
beakr <- newBeakr()
# beakr pipeline
beakr %>%
# Enable CORS
cors() %>%
# Respond to GET requests at the "/hi" route
httpGET(path = "/hi", function(req, res, err) {
print("Hello, World!")
}) %>%
# Respond to GET requests at the "/bye" route
httpGET(path = "/bye", function(req, res, err) {
print("Farewell, my friends.")
}) %>%
# Start the server on port 25118
listen(host = "127.0.0.1", port = 25118, daemon = TRUE)
# ------------------------------------------------------------
# POINT YOUR BROWSER AT:
# * http://127.0.0.1:25118/hi
# * http://127.0.0.1:25118/bye
#
# THEN, STOP THE SERVER WITH stopServer(beakr)
# ------------------------------------------------------------
# Stop the beakr instance server
stopServer(beakr)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.