Skip to content

Commit

Permalink
CORS
Browse files Browse the repository at this point in the history
  • Loading branch information
hillalex committed Aug 27, 2024
1 parent 76e34e1 commit 746dfb5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion R/router.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
build_routes <- function() {
if (!dir.exists("uploads")) {
dir.create("uploads")
}
plumber::options_plumber(trailingSlash = TRUE)
pr <- porcelain::porcelain$new(validate = TRUE)
pr$registerHook(stage = "preserialize", function(data, req, res, value) {
res$setHeader("Access-Control-Allow-Origin", "http://localhost:3000")
if (!is.null(req$HTTP_ORIGIN) &&
req$HTTP_ORIGIN %in% c("http://localhost:3000", "http://localhost")) {
# allow local app and integration tests to access endpoints
res$setHeader("Access-Control-Allow-Origin", req$HTTP_ORIGIN)
}
value
})

Expand Down

0 comments on commit 746dfb5

Please sign in to comment.