/
serving-your-own-site.Rmd
78 lines (55 loc) · 2.09 KB
/
serving-your-own-site.Rmd
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
---
title: "Serving your own site"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Serving your own site}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
outdir <- here::here("_api")
```
```{r setup}
library(sysreqs)
```
You may have the need to serve your own version of this site locally. If that is the case, you can do so quite easily. There are two steps to hosting your own version of the site/API. First, you must download the requisite json files and store them in their own directory. Second, you must serve them on a server. Since this is only plain-text, you can serve it on Netlify (my choice) or Github pages. sysreqs also provides a function for serving them locally.
## Create the directories
You can create your own directories using `create_sysreqs_site()` and specifying the output directory.
```{r message=FALSE, eval = FALSE}
outdir <- "_api"
create_sysreqs_site(outdir)
```
Check the output directory.
```{r}
list.files(outdir)
```
## Serve the site
We can serve the site locally using `serve_sysreqs()` and providing the directory containing the json files that we need. This will create an `httpuv` server that runs in the background.
By default this runs on `localhost:8080` you can change this by setting the `host` and `port` arguments your self.
```{r}
serve_sysreqs(outdir)
```
We can check if this is working by using `httr` to call the local server.
```{r}
httr::GET("http://localhost:8080/patterns.json")
```
Awesome! If we want to use this server for our `get_pkg_sysreqs()` and other functions we need to change the environment variable `SYSREQS_URL`. By default it is set to `r Sys.getenv("SYSREQS_URL")`.
```{r}
Sys.setenv("SYSREQS_URL" = "http://localhost:8080")
```
We can check if this is correct using the internal function `b_url()` which assigns the base url for http queries.
```{r}
sysreqs:::b_url()
```
Let's now try out one of the package's functions.
```{r}
sysreqs::fetch_systems()
```
Stop serving the site.
```{r}
stop_sysreqs()
```