Skip to content

Commit

Permalink
doc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
terrablue committed Feb 27, 2024
1 parent 325aed0 commit 724d0e5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 34 deletions.
33 changes: 14 additions & 19 deletions docs/guide/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ If Primate doesn't find a `primate.config.js` in your project root directory
(the directory where your `package.json` resides) or this file does not export
a default object, Primate will fall back to its default configuration file.

```js caption=default configuration
```js
import { identity } from "rcompat/function";
import { Logger } from "primate";

Expand Down Expand Up @@ -66,7 +66,7 @@ To illustrate this, if you wanted to change the default logging level to
`Info` instead of `Warn` and the HTTP port to `6262` you would create a
`primate.config.js` in your project root with the following overrides.

```js caption=custom configuration
```js
import { Logger } from "primate";

export default {
Expand All @@ -82,7 +82,7 @@ export default {
Primate will merge your custom configuration with its default, resulting in
effectively the following configuration.

```js caption=merged configuration
```js
import { identity } from "rcompat/function";
import { Logger } from "primate";

Expand Down Expand Up @@ -168,8 +168,7 @@ Name of the default error HTML page located in `location.pages`. If

## Logging options

For more info on logging, refer to the [Logging in Primate](/guide/logging)
section.
For more info on logging, refer to the [Logging](/guide/logging) section.

### logger.level

Expand Down Expand Up @@ -226,7 +225,7 @@ If you wanted a fairly restrictive policy, you would use something like this.
}
```

If existing, `script-src` and `style-src` will be concatenated with hashes of
If existing, `script-src` and `style-src` will be concatenated with hashes of
scripts and styles picked up by Primate (either through the `components` or the
`static` directory).

Expand All @@ -249,10 +248,10 @@ If specified as a relative path, will be relative to project root.

!!!
Primate does not load the key or certificate into memory. It only resolves
their paths as necessary and passes them to the [rcompat](https://github.com/rcompat/rcompat).
their paths as necessary and passes them to [rcompat][rcompat].
!!!

### Request options
## Request options

### request.body.parse

Expand All @@ -264,7 +263,7 @@ forwarding the requests to another app. The headers, the querystring and
cookies will be still parsed and available to `request`, and
`request.original` will contain the untouched original request.

### Location options
## Location options

Locations of Primate standard directories. If any of these locations are
relative, they will be relative to project root.
Expand Down Expand Up @@ -303,8 +302,8 @@ The directory from which static assets are copied to the build directory at

Default `"types"`

The directory where types are located. [Types](/guide/types) can be
used to limit the range of possible values that a variable can hold.
The directory where types are located. [Types](/guide/types) can be used to
limit the range of possible values that a variable can have in runtime.

### location.build

Expand All @@ -315,8 +314,8 @@ is recreated during every run.

### location.client

The directory into which client files (compiled components, modules) are copied
and from which they are served at runtime.
The directory into which client files (compiled components and dependencies)
are copied and from which they are served at runtime.

### location.server

Expand All @@ -331,7 +330,7 @@ Modifying aspects of the build system and the resulting server/client code.

Default `[]`

A list of directories to be included in the server and client build. May not
A list of directories to be included in the server and client build. Must not
be any known Primate location.

### build.index
Expand All @@ -354,18 +353,14 @@ Default `_ => _` (identity function)

A file content mapper for the files specified in `build.transform.files`.

## Type options

Configuring [runtime types](/guide/types).

## pages/app.html

If you use the `view` or `html` [handler](/guide/responses#view), Primate will
embed the generated HTML from the handler into this file. If an `app.html`
doesn't exist in the `pages` directory, Primate will fall back to its default
app page.

```html caption=dafault app page
```html
<!doctype html>
<html>
<head>
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/responses.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ import { ws } from "primate";

export default {
get(request) {
const { limit } = request.query.get() ?? 20;
const limit = request.query.get("limit") ?? 20;
let n = 1;
return ws({
open(socket) {
Expand Down
22 changes: 12 additions & 10 deletions docs/guide/routes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Primate uses filesystem-based routes. Route files are JavaScript files in the
`routes` directory that correspond to their routes. For example, the file
at `routes/user/profile.js` is used to handle a client accessing
`/user/profile`. The path may include parameters in braces, which are
`/user/profile`. The path may include parameters in brackets, which are
mapped to `request.path`, and which may have types.

To illustrate this, consider that inside `routes`
Expand Down Expand Up @@ -34,16 +34,16 @@ export default {
```

In this example, accessing the path `/user/profile` using any of the specified
verbs will return a plain-text response as specified.
verbs will return a plain-text response with the given string.

## The request object

Route verb functions accept a single parameter representing request data. This
aggregate object allows easy access to the request `body`, any `path`
parameters defined with braces, the `query` string split into parts, `cookies`
as well as other `headers` and a reference to the `original` WHATWG Request
object. The aggregate nature of this object allows you to pull in what you need
using object destructuring.
parameters defined with brackets, the `query` string split into parts,
`cookies` as well as other `headers` and a reference to the `original` WHATWG
Request object. The aggregate nature of this object allows you to pull in what
you need using object destructuring.

### body

Expand All @@ -66,7 +66,9 @@ used in the request.

* `application/x-www-form-urlencoded`, which is primarily used in HTML forms,
decodes the form fields into object properties
* `application/json` will decode the given JSON string using `JSON.parse`
* `application/json` decodes the given JSON string using `JSON.parse`
* `multipart/form-data` decodes the given form using `FormData`, making files
available as `Blob` objects and other fields as normal object properties

```js caption=routes/your-full-name.js
export default {
Expand Down Expand Up @@ -198,15 +200,15 @@ WHATWG Request object.

## Parameters

Route paths may contain parameters in braces, which indicate they will be
Route paths may contain parameters in brackets, which indicate they will be
mapped to `request.path`. Path parameter names are case sensitive, and a
request may contain any number of them, though it must not contain the same
parameter in the same case twice. They must be non-empty, that is matched by
at least one character.

By default, parameters will match anything in the path except `/`, though they
are not greedy. A path like `/users/[userId]a.js` is unambiguous: it will match
any path that starts with `/users/` followed by anything that is not `/`,
are not greedy. A path like `/users/[user_id]a.js` is unambiguous: it will
match any path that starts with `/users/` followed by anything that is not `/`,
provided that it ends with `a`. The last `a` can therefore not be part of
the match.

Expand Down
7 changes: 3 additions & 4 deletions docs/guide/use-cases.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ change [`location.static`][location-static] or

## API

Primate's [filesystem-based routes][routes] are excellent for creating an API.
Primate generally follows the OpenAPI specification in denoting path parameters
with braces (`{}`) and making the body and path, query, cookie and header
parameters easily accessible to the route function.
Primate's [filesystem-based routes][routes] are excellent for creating an API,
making the body and path, query, cookie and header parameters easily accessible
to the route function.

```js caption=routes/comment/[commentId].js
export default {
Expand Down

0 comments on commit 724d0e5

Please sign in to comment.