...
 
Commits (5)
......@@ -9,15 +9,6 @@
"extends": [
"@hapi/eslint-config-hapi"
],
"plugins": [
"svelte3"
],
"overrides": [
{
"files": ["**/*.svelte"],
"processor": "svelte3/svelte3"
}
],
"rules": {
"indent": [
2,
......
image: node:14
stages:
- lint
before_script:
- npm install
lint:
stage: lint
script:
- npm run lint
# Forum
# Forum Server
A forum for the year 3000.
A forum server for the year 3000.
## Running the server
## About Forum Server
This project provides a [docker compose][docker-compose] configuration
to easily run the service. In order to run the server, run
`docker-compose up`
This project is the service that provides the data for [forum][forum].
It exposes a web socket through which the frontend can subscribe to
different data stores to get notified when changes occur, and provides
a set of commands to modify this data.
## Usage Guide for Frontend Applications
### Connecting
Connect to the exposed web socket by using the exposed URL
```
const socket = new WebSocket('https://server.address:1978');
```
### Reading Changefeeds
To subscribe to data, add an event listener for the `message` event.
```
socket.addEventListener('message', (message) => {
// do things
}
```
And then parse the event. The [message event][message-event] will have
the following format:
```
{
data: {
name: <event_name>,
data: <event_payload>
}
}
```
For reference on the available events and their payloads, check
below.
## What you will need to get started
### Emitted Events
#### Changefeeds
These events will have the name `changefeed:<changefeed_name>`. The
payload in their `data` property will be a [RethinkDB Change][rethinkdb-change].
The available changefeed events are:
* `changefeed:forums`: The list of forums
## Setup Guide for Developers
### What you will need to get started
This project uses [node][node] for most of its development processes.
Once you have node installed according to the instructions there, run
`npm install` from the root of the project.
`npm install` from the root of the project. This will install the required
project dependencies.
To run the server, this project uses [docker][docker]. Once you have
docker installed according to the instructions there, check out the
instructions under "Running the server"
For local development serve the page by running `npm watch` from the
root of the project.
### Running the server
## Installing git hooks
This project provides a [docker compose][docker-compose] configuration
to easily run the service. In order to run the server, run
`docker-compose up`. This will run two services: one containing the
forum server itself, and another one using the database.
### Code Style
This repo contains a pre-commit git hook so indent will run before every
This project follows the [Hapi Styleguide][hapi-styleguide] and uses
[eslint][eslint] to enforce it. If you install the included git hooks
it will check eslint before every commit. And on every push, it will
run a build to check whether the style guide is followed. Otherwise
merges will not be accepted.
### Installing git hooks
This repo contains a pre-commit git hook so eslint will run before every
commit. Run `npm run setup-hooks` to install it.
## Running migrations on the docker environment
### Running migrations on the docker environment
After building the app with docker compose, you can set up the database
with `docker exec forum_forum_1 npm run db:setup`. This will run
......@@ -34,13 +99,15 @@ If you only want to run migrations, you should run
If you only want to seed the database, you should run
`docker exec forum_forum_1 npm run db:seed` instead.
## Accessing the database control panel
### Accessing the database control panel
This project uses rethinkdb as a database, which exposes an
admin panel on port 8080. You can open it in a browser by
running `npm run db:admin` which will open `http://localhostt:8080`
running `npm run db:admin` which will open `http://localhost:8080`
## Development Guide
## Creating migrations for the database
### Creating migrations for the database
This project uses `migrate` to create and run migrations in the
database. If you want to create, modify or remove a table you
......@@ -67,4 +134,11 @@ The file `db/helpers.js` has a set of helper functions for some common
operations used when dealing with the database: gettting a connection
to the database, and getting a connection with a database selected.
[docker]: https://www.docker.com/
[docker-compose]: https://docs.docker.com/compose/
[eslint]: https://eslint.org/
[forum]: https://gitlab.com/rbdr/forum
[hapi-styleguide]: https://hapi.dev/policies/styleguide/
[message-event]: https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent
[node]: https://nodejs.org/en/
[rethinkdb-change]: https://rethinkdb.com/api/javascript/changes
'use strict';
const Http = require('http');
const Path = require('path');
const WebSocket = require('ws');
const HandleErrors = require('./middleware/handle_errors.js');
const SocketCoordinator = require('./sockets/coordinator');
......
#!/usr/bin/env sh
npm run linthtml
npm run lint