Skip to content
This repository was archived by the owner on Oct 24, 2021. It is now read-only.

Commit 9a949c2

Browse files
committed
Move documentation to apibox
1 parent e379746 commit 9a949c2

File tree

1 file changed

+11
-51
lines changed

1 file changed

+11
-51
lines changed

source/packages/webapp.md

Lines changed: 11 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,8 @@ WebApp.connectHandlers.use('/hello', (req, res, next) => {
2525
});
2626
```
2727

28-
`WebApp.connectHandlers.use([path], handler)` has two arguments:
29-
30-
**path** - an optional path field.
31-
This handler will only be called on paths that match
32-
33-
this string. The match has to border on a `/` or a `.`. For example, `/hello`
34-
will match `/hello/world` and `/hello.world`, but not `/hello_world`.
35-
36-
**handler** - this is a function that takes three arguments:
37-
38-
- **req** - a Node.js
39-
[IncomingMessage](https://nodejs.org/api/http.html#http_class_http_incomingmessage)
40-
object with some extra properties. This argument can be used to get information
41-
about the incoming request.
42-
- **res** - a Node.js
43-
[ServerResponse](http://nodejs.org/api/http.html#http_class_http_serverresponse)
44-
object. Use this to write data that should be sent in response to the
45-
request, and call `res.end()` when you are done.
46-
- **next** - a function. Calling this function will pass on the handling of
47-
this request to the next relevant handler.
28+
{% apibox "WebApp.connectHandlers" %}
29+
{% apibox "connectHandlersCallback(req, res, next)" %}
4830

4931
### Serving a Static Landing Page
5032

@@ -125,7 +107,7 @@ And finally, if you decide to use this technique you'll want to make sure you un
125107
In some cases it is valuable to be able to control the __meteor_runtime_config__ variable that initializes Meteor at runtime.
126108

127109
#### Example
128-
There are occasions when a single Meteor server would like to serve multiple cordova applications that have each have a unique `ROOT_URL`. But there are 2 problems:
110+
There are occasions when a single Meteor server would like to serve multiple cordova applications that each have a unique `ROOT_URL`. But there are 2 problems:
129111
1. The Meteor server can only be configured to serve a single `ROOT_URL`.
130112
2. The `cordova` applications are build time configured with a specific `ROOT_URL`.
131113

@@ -134,7 +116,6 @@ These 2 conditions break `autoupdate` for the cordova applications. `cordova-plu
134116
To remedy this problem `webapp` has a hook for dynamically configuring `__meteor_runtime_config__` on the server.
135117

136118
#### Dynamic Runtime Configuration Hook
137-
Register a callback when the meteor runtime configuration, `__meteor_runtime_config__` is being sent to the client.
138119
```js
139120
WebApp.addRuntimeConfigHook(({arch, request, encodedCurrentConfig, updated}) => {
140121
// check the request to see if this is a request that requires
@@ -154,36 +135,20 @@ WebApp.addRuntimeConfigHook(({arch, request, encodedCurrentConfig, updated}) =>
154135
return undefined;
155136
})
156137
```
157-
158-
`WebApp.addRuntimeConfigHook(handler)` has one argument:
159-
160-
**handler** - The `handler` is called on each request for the root page which has `__meteor_runtime_config__` defined in it. The handler takes a single options argument with the following properties:
161-
162-
- **arch** - _String_. the architecture being responded to. This can be one of `web.browser`, `web.browser.legacy` or `web.cordova`.
163-
- **request** - a Node.js
164-
[IncomingMessage](https://nodejs.org/api/http.html#http_class_http_incomingmessage)
165-
object with some extra properties. This argument can be used to get information
166-
about the incoming request.
167-
- **encodedCurrentConfig** - _String_. the current configuration object encoded as a string for inclusion in the root html.
168-
- **updated** - _Boolean_. `true` if the config for this architecture been updated since last called, otherwise `false`. This flag can be leveraged to cache the decoding/encoding for each architecture.
169-
170-
If the handler returns a _falsy_ value the hook will not modify the runtime configuration.
171-
172-
If the handler returns a _String_ the hook will substitute the string for the encoded configuration string. **Warning:** the hook does not check the return value at all it is the responsibility of the caller to get the formatting correct using the helper functions.
138+
{% apibox "WebApp.addRuntimeConfigHook" %}
139+
{% apibox "addRuntimeConfigHookCallback(options)" %}
173140

174141
Additionally, 2 helper functions are available to decode the runtime config string and encode the runtime config object.
175142

176-
`WebApp.decodeRuntimeConfig(encoded_config_string)`: returns a config object from an encoded config string.
177-
`WebApp.encodeRuntimeConfig(config_object)`: returns an encoded string from a config object that is ready for the root page.
178-
179-
The expected usage is to decode the runtime config string, operate on the object and then return the encoded runtime configuration.
143+
{% apibox "WebApp.decodeRuntimeConfig" %}
144+
{% apibox "WebApp.encodeRuntimeConfig" %}
180145

181146
### Updated Runtime Configuration Hook
182-
Register a callback on updates to the configuration runtime.
183147
```js
184148
const autoupdateCache;
185149
// Get a notification when the runtime configuration is updated
186-
WebApp.addUpdatedConfigHook(({arch, manifest, runtimeConfig}) => {
150+
// for each arch
151+
WebApp.addUpdatedNotifyHook(({arch, manifest, runtimeConfig}) => {
187152
// Example, see if runtimeConfig.autoupdate has changed and if so
188153
// do something
189154
if(!_.isEqual(autoupdateCache, runtimeConfig.autoupdate)) {
@@ -193,10 +158,5 @@ WebApp.addUpdatedConfigHook(({arch, manifest, runtimeConfig}) => {
193158
})
194159
```
195160

196-
`WebApp.addUpdatedConfigHook(handler)` has one argument:
197-
198-
**handler** - The `handler` is called on every change to an `arch` runtime configuration. The handler takes a single options argument with the following properties:
199-
200-
- **arch** - _String_. the architecture being responded to. This can be one of `web.browser`, `web.browser.legacy` or `web.cordova`.
201-
- **manifest** - _Object_. the manifest object.
202-
- **runtimeConfig** - _Object_. the new updated configuration object for this `arch`.
161+
{% apibox "WebApp.addUpdatedNotifyHook" %}
162+
{% apibox "addUpdatedNotifyHookCallback(options)" %}

0 commit comments

Comments
 (0)