rexyai / RestRserve

R web API framework for building high-performance microservices and app backends
https://restrserve.org
276 stars 32 forks source link

[BUG] slow to serve static file and swagger UI must use CDN #197

Open mentik opened 1 year ago

mentik commented 1 year ago

this bug report was ported from [https://github.com/rexyai/RestRserve/issues/196] @s-u @dselivanov

For example:

api$add_static(
  path = "/statics/",
  file_path = "statics/",
  content_type = NULL
)

i also try the swagger ui, and i see more faster rendering when using jinjar packages rather than using the built-in function. Sometimes on portrainer docker deployment, the swagger built-in function return "404 Not Found".

i try this code:

# ---- /swagger ----

api$add_static(
  path = "/swagger/openapi.yaml",
  file_path = "openapi.yaml",
  content_type = "application/x-yaml"
)

api$add_static(
  path = "/swagger/",
  file_path = "/swagger/",
  content_type = NULL
)

swaggerVAR <- list(path_swagger_assets = paste0("https://",cdnURL,"/swagger"),
                   path_openapi = "/swagger/openapi.yaml")
swaggerHTML <- jinjar::render(parse_template(fs::path("swagger/index.html")), !!!swaggerVAR)
api$add_get(
  path = "/swagger",
  FUN = function(request, response) {
    response$set_content_type("text/html; charset=utf-8")
    response$set_body(swaggerHTML)
  }
)

thank you in advanced

R version: 4.2.2 Platforms tested: Windows 11, Docker Offline WSL, Docker Online Portrainer