Skip to content

Commit

Permalink
migrate docs to docusaurus
Browse files Browse the repository at this point in the history
  • Loading branch information
Thiht committed Mar 4, 2024
1 parent e52afb4 commit 2703480
Show file tree
Hide file tree
Showing 52 changed files with 19,501 additions and 26 deletions.
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.parcel-cache/
.vscode/
build/
docs/.vuepress/dist/
node_modules/
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
.vscode/
build/
coverage/
docs/.vuepress/dist/
node_modules/
sessions/
smocker
Expand Down
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h1 align="center">
<img src="docs/.vuepress/public/logo/logo-horizontal.png" alt="Smocker" height="100" title="Smocker logo by mandyellow" />
<img src="docs/static/img/logo-horizontal.png" alt="Smocker" height="100" title="Smocker logo by mandyellow" />
</h1>

[![CI](https://github.com/Thiht/smocker/actions/workflows/main.yml/badge.svg)](https://github.com/Thiht/smocker/actions/workflows/main.yml)
Expand Down Expand Up @@ -65,9 +65,9 @@ curl localhost:8081/version

Smocker exposes a configuration user interface. You can access it in your web browser on http://localhost:8081/.

![History](docs/.vuepress/public/screenshots/screenshot-history.png)
![History](docs/static/screenshots/screenshot-history.png)

![Mocks](docs/.vuepress/public/screenshots/screenshot-mocks.png)
![Mocks](docs/static/screenshots/screenshot-mocks.png)

## Usage

Expand Down Expand Up @@ -162,12 +162,11 @@ The frontend is written with TypeScript and React. You can use the following com

### Documentation

The documentation is written in Markdown using [Vuepress](https://vuepress.vuejs.org/). You can use the following commands to manage the documentation:
The documentation is written in Markdown using [Docusaurus](https://docusaurus.io). You can use the following commands in the `docs/` folder to manage the documentation:

- `yarn install`: install the dependencies
- `yarn docs:generate`: regenerate documentation screenshots (require the whole application to be started on the default ports)
- `yarn docs:dev`: start the documentation in development mode, with live reload
- `yarn docs:build`: generate the static production documentation
- `npm install`: install the dependencies
- `npm run start`: start the documentation in development mode, with live reload
- `npm run build`: generate the static production documentation

### Docker

Expand Down
20 changes: 20 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Dependencies
/node_modules

# Production
/build

# Generated files
.docusaurus
.cache-loader

# Misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
3 changes: 3 additions & 0 deletions docs/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: [require.resolve("@docusaurus/core/lib/babel/preset")],
};
7 changes: 7 additions & 0 deletions docs/docs/guide/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"label": "Guide",
"position": 1,
"link": {
"type": "generated-index"
}
}
115 changes: 115 additions & 0 deletions docs/docs/guide/getting-started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
---
sidebar_position: 3
---

# Getting Started

Smocker exposes two ports:

- `8080` is the mock server port. It will expose the routes you register through the configuration port.
- `8081` is the configuration port. It's the port you will use to register new mocks. This port also exposes a user interface.

To get a better understanding of how Smocker works, let's open its user interface on the browser. With the default configuration, it will be available on [localhost:8081](http://localhost:8081/)

![Smocker's user interface - Empty History](/screenshots/screenshot-empty-history.png)

If you take a look at the sidebar on the left, you can see a list of sessions with one selected element.

![Smocker's user interface - Sessions sidebar](/screenshots/screenshot-sessions.png)

By default, Smocker will automatically create a **session** on the first call trying to retrieve **history** or **mocks**.
But you can also create one using the [API](/docs/technical-documentation/api#start-session).
Smocker shows the history of the calls made to the mock server for the selected session. As we just started it, nothing is displayed yet.

Let's see how Smocker reacts when we try to call a non existing route. Run the following command in a terminal:

<details>
<summary><code>curl -i localhost:8080/hello/world</code></summary>

```
HTTP/1.1 666 status code 666
Content-Type: application/json; charset=UTF-8
Date: Wed, 29 Jan 2020 17:25:31 GMT
Content-Length: 206
{"message":"No mock found matching the request","request":{"path":"/hello/world","method":"GET","body":"","headers":{"Accept":["*/*"],"User-Agent":["curl/7.54.0"]},"date":"2020-01-29T17:25:31.956225978Z"}}
```

</details>

If you refresh Smocker's user interface, you will see that it now displays an entry in the history:

![Smocker's user interface - History with an undeclared mock response](/screenshots/screenshot-history-666.png)

Let's look closer at the call:

- on the left, you can see all the details of the request you made: method `GET`, path `/hello/world`, and headers,
- on the right, you can see the response of Smocker: error code `666`, and informations regarding the error.

![Smocker's user interface - Entry with an undeclared mock response](/screenshots/screenshot-hello-world-666.png)

:::note
Smocker reserves the non HTTP status codes from `600` to `699`. This is because we need an out of protocol way to report Smocker errors, which are different from the standard protocol errors. The explicit list of Smocker custom errors is available [here](/docs/technical-documentation/errors).
:::

To register our first mock, we will use the user interface. Switch to the "Mocks" page and click on the "Add Mock" button.

![Smocker's user interface - Empty mocks page](/screenshots/screenshot-empty-mocks.png)

![Smocker's user interface - Add mocks](/screenshots/screenshot-add-mocks.png)

Mocks are defined using the YAML format. Register the following mock:

```yml
- request:
method: GET
path: /hello/world
response:
headers:
Content-Type: application/json
body: >
{
"hello": "Hello, World!"
}
```
This mock simply states that when an HTTP `GET` call is made on the `/hello/world` path, the mock server must return a basic JSON document.

Now, execute the previous call one more time:

<details>
<summary><code>curl -i localhost:8080/hello/world</code></summary>

```
HTTP/1.1 200 OK
Content-Type: application/json
Date: Wed, 29 Jan 2020 17:40:52 GMT
Content-Length: 30

{
"hello": "Hello, World!"
}
```
</details>
Once you refresh the user interface, you should notice that this last call is present in the history and that Smocker replied with the response we declared instead of an error!
![Smocker's user interface - History with an valid mock response](/screenshots/screenshot-hello-world-200.png)
You can also visualize call history as a **sequence diagram** by clicking on the `visualize` button on the top right of the page.
![Smocker's user interface - History visualization](/screenshots/screenshot-history-visualize.png)
This covers the basic usage of Smocker, but it was just the beginning! Smocker covers many more topics:
- advanced filters,
- automation,
- dynamic calls,
- proxies,
- contexts,
- and everything you might need to mock your whole environment!
For more details and explanations than just a **Hello World**, we invite you to check the [Real Life Usage](./real-life) section.
And for advanced mocks you can check the [Mock Definition](/docs/technical-documentation/mock-definition) documentation.
71 changes: 71 additions & 0 deletions docs/docs/guide/installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
sidebar_position: 2
---

# Installation

Smocker can be installed either with [Docker](https://www.docker.com/) or manually on any Linux system, depending on your needs.

## With Docker

```sh
docker run -d \
--restart=always \
-p 8080:8080 \
-p 8081:8081 \
--name smocker \
thiht/smocker
```

or with TLS enabled:

```sh
docker run -d \
--restart=always \
-p 44300:8080 \
-p 44301:8081 \
-e SMOCKER_TLS_ENABLE=true \
-v /path/to/your/cert.pem:/etc/smocker/tls/certs/cert.pem:ro \
-v /path/to/your/key.pem:/etc/smocker/tls/private/key.pem:ro \
--name smocker \
thiht/smocker
```

## Manual Deployment

:::note
The official binaries are currently built for Linux only. This is not a hard limit though, as the source code should be fully compatible with most of the standard platforms.
:::

```sh
# This will be the deployment folder for the Smocker instance
mkdir -p /opt/smocker && cd /opt/smocker
wget -P /tmp https://github.com/Thiht/smocker/releases/latest/download/smocker.tar.gz
tar xf /tmp/smocker.tar.gz
rm /tmp/smocker.tar.gz

nohup ./smocker -mock-server-listen-port=8080 -config-listen-port=8081 &

# Or with TLS

# The certificate is expected in /etc/smocker/tls/certs/ by default
# You can override it with -tls-cert-file and -tls-private-key-file
nohup ./smocker -mock-server-listen-port=44300 -config-listen-port=44301 -tls-enable &
```

## Healthcheck

To check that Smocker started successfully, just run the following command:

```sh
curl localhost:8081/version
```

or with TLS enabled:

```sh
curl https://localhost:44301/version

# Or if you use a self signed certificate
curl -k https://localhost:44301/version
```
Loading

0 comments on commit 2703480

Please sign in to comment.