From f6750d5776652a9a8f3ae9d7e4ae4d53251ac68b Mon Sep 17 00:00:00 2001 From: Riyadh Zenasni Date: Wed, 8 Feb 2017 20:22:12 +0100 Subject: [PATCH 1/3] Update @horizon/server and express to latest version --- examples/express-server/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/express-server/package.json b/examples/express-server/package.json index cc544b125..9593989a8 100644 --- a/examples/express-server/package.json +++ b/examples/express-server/package.json @@ -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", From 0a9336f3ae00ab61e82920119263c1b4ff067bc7 Mon Sep 17 00:00:00 2001 From: Riyadh Zenasni Date: Sat, 11 Feb 2017 21:58:32 +0100 Subject: [PATCH 2/3] Update example app, change allow_unauthenticated and project_name --- examples/express-server/main.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/examples/express-server/main.js b/examples/express-server/main.js index 64b934e2f..691bff773 100755 --- a/examples/express-server/main.js +++ b/examples/express-server/main.js @@ -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.'); From d769ac5f4b0e90b91fd08b9f1bfbee8180658704 Mon Sep 17 00:00:00 2001 From: Riyadh Zenasni Date: Sat, 11 Feb 2017 22:04:09 +0100 Subject: [PATCH 3/3] Add README.md to express-server example --- examples/express-server/README.md | 44 +++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 examples/express-server/README.md diff --git a/examples/express-server/README.md b/examples/express-server/README.md new file mode 100644 index 000000000..034fdc855 --- /dev/null +++ b/examples/express-server/README.md @@ -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. + + + + + + + + +