-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.R
34 lines (27 loc) · 853 Bytes
/
app.R
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(plumber)
# remove warning from logs
options(warn = -1)
# load required helpers
source("./helpers/env.R")
source("./helpers/error.R")
source("./helpers/logging.R")
source("./helpers/parallel.R")
source("./helpers/validator.R")
# App initialization
app <- pr()
# redirect to slashed endpoint, /hello to /hello/
options_plumber(trailingSlash = TRUE)
# Plumbber settings
app %>%
pr_set_error(error_handler) %>%
pr_hooks(list(preroute = pre_route_logging, postroute = post_route_logging))
# 'file based' routing
r_routes_file_names = list.files(path = './routes' ,full.names=TRUE, recursive=TRUE)
for (file_name in r_routes_file_names) {
routeName = substring(file_name, 10, nchar(file_name) - 2)
app %>%
pr_mount(routeName, pr(file_name) %>% pr_set_error(error_handler))
}
# run plumber
app %>%
pr_run(host = HOST, port = PORT)