Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update express-server example to latest version #868

Open
wants to merge 3 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions examples/express-server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

#Embedding horizon within express

This folder contains a simple example that shows how to embed horizon within an express server. This offers the opportunity to integrate horizon at different stages with an express app.

###Before we start
Make sure that you have the latest version of horizon installed. [Installing horizon](http://horizon.io/install/).
At the same time make sure that you have rethinkdb installed. [Installing rethinkdb](https://www.rethinkdb.com/docs/install/).

###Running the example
Let's initialize our app using horizon cli, we will call this app **example_app**.

```
hz init example_app
```
Let's turn on rethinkdb which will by default listen at port 28015.
```
rethinkdb
```
the **hz init** command will create a directory for us called example_app (which is the app name), now we will go to that directory.

```
cd example_app
```
Our default schema is found in **.hz** directory, to apply that schema we run the following command.
```
hz schema apply .hz/schema.toml
```
Copy the files of this repo (main.js and package.json) to our example_app directory, then run the following commands

```
npm i
node main.js
```
That's it. Head to http://localhost:8181 to see the example app running.









13 changes: 12 additions & 1 deletion examples/express-server/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,19 @@ const express = require('express');
const horizon = require('@horizon/server');

const app = express();

app.use(express.static('./dist'));

const http_server = app.listen(8181);
const options = { auth: { token_secret: 'my_super_secret_secret' } };
const options = {
project_name: 'example_app',
auth: {
token_secret: 'my_super_secret_secret',
// make sure that the following is set to true, otherwise
// horizon client wont be able to connect using default constructor
allow_unauthenticated: true,
},
};
const horizon_server = horizon(http_server, options);

console.log('Listening on port 8181.');
4 changes: 2 additions & 2 deletions examples/express-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"author": "RethinkDB",
"license": "MIT",
"dependencies": {
"@horizon/server": "^1.0.1",
"express": "^4.13.3"
"@horizon/server": "^2.0.0",
"express": "^4.14.1"
},
"repository": {
"type": "git",
Expand Down