Skip to content

Commit

Permalink
Merge pull request #54 from nzzdev/release-2.2.0
Browse files Browse the repository at this point in the history
Release 2.2.0
  • Loading branch information
fuenkchen committed Jun 13, 2017
2 parents 44ef8b8 + 511b766 commit e22ce10
Show file tree
Hide file tree
Showing 14 changed files with 850 additions and 544 deletions.
25 changes: 17 additions & 8 deletions auth/couchdb-cookie/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ const Joi = require('joi');
const Boom = require('boom');
const fetch = require('node-fetch');

function getDbUrl(server) {
let dbUrl = server.settings.app.misc.get('/authStrategy/couchdb_cookie/db/host');
if (!dbUrl) {
dbUrl = server.settings.app.misc.get('/authStrategy/couchdb_cookie/couchdbHost');
}

if (!dbUrl.startsWith('http')) {
dbUrl = `${server.settings.app.misc.get('/authStrategy/couchdb_cookie/db/protocol') || 'https'}://${dbUrl}`;
}
return dbUrl;
}

module.exports = [
{
path: '/authenticate',
Expand Down Expand Up @@ -56,9 +68,8 @@ module.exports = [
}
},
handler: (request, reply) => {
const db = request.server.settings.app.misc.get('/db');

fetch(`${db.host}/_users/org.couchdb.user:${request.auth.credentials.name}`, {
const dbUrl = getDbUrl(request.server);
fetch(`${dbUrl}/_users/org.couchdb.user:${request.auth.credentials.name}`, {
headers: {
'Cookie': `AuthSession=${request.state['AuthSession']};`
}
Expand Down Expand Up @@ -97,9 +108,8 @@ module.exports = [
}
},
handler: (request, reply) => {
const db = request.server.settings.app.misc.get('/db');

fetch(`${db.host}/_users/org.couchdb.user:${request.auth.credentials.name}`, {
const dbUrl = getDbUrl(request.server);
fetch(`${dbUrl}/_users/org.couchdb.user:${request.auth.credentials.name}`, {
headers: {
'Cookie': `AuthSession=${request.state['AuthSession']};`
}
Expand All @@ -115,7 +125,7 @@ module.exports = [
})
.then(data => {
let newUserData = Object.assign(data, request.payload);
return fetch(`${db.host}/_users/org.couchdb.user:${request.auth.credentials.name}`, {
return fetch(`${dbUrl}/_users/org.couchdb.user:${request.auth.credentials.name}`, {
method: 'PUT',
headers: {
'Cookie': `AuthSession=${request.state['AuthSession']};`
Expand All @@ -127,7 +137,6 @@ module.exports = [
if (response.ok) {
return reply('ok')
} else {
console.log(response)
return reply(Boom.internal());
}
})
Expand Down
11 changes: 9 additions & 2 deletions auth/couchdb-cookie/strategy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
const server = require('../../server.js').getServer();

const db = server.settings.app.misc.get('/db');
let dbUrl = server.settings.app.misc.get('/authStrategy/couchdb_cookie/db/host');
if (!dbUrl) {
dbUrl = server.settings.app.misc.get('/authStrategy/couchdb_cookie/couchdbHost');
}

if (!dbUrl.startsWith('http')) {
dbUrl = `${server.settings.app.misc.get('/authStrategy/couchdb_cookie/db/protocol') || 'https'}://${dbUrl}`;
}

server.auth.strategy('q-auth', 'couchdb-cookie', {
couchdbUrl: db.host
couchdbUrl: dbUrl
});
5 changes: 3 additions & 2 deletions db.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ const nano = require('nano')
var db;

module.exports.connect = function(config) {
console.log(`Connecting to database https://${config.host}/${config.database}`);
const dbUrl = `${config.protocol || 'https'}://${config.host}/${config.database}`;
console.log(`Connecting to database ${dbUrl}`);
db = nano({
url: `https://${config.host}/${config.database}`,
url: dbUrl,
requestDefaults: {
auth: {
user: config.user,
Expand Down
2 changes: 2 additions & 0 deletions docs/_data/navigation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ main:
url: developing-tools.html
- title: "Rendering Info?"
url: rendering-info.html
- title: "toolRuntimeConfig"
url: tool-runtime-config.html
- title: "Migrations"
url: "migrations.html"
13 changes: 12 additions & 1 deletion docs/rendering-info.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,24 @@ title: Rendering Info
We use the term `rendering info` to describe the HTTP response from a request to _q-server/rendering-info/{id}/{target}_. This request is typically sent by a so called Q loader. Examples of Q loaders are the preview in Q editor or the browser based loader used in the [demo](https://q-demo.st.nzz.ch). The source for this browser based loader can be found on Github: [nzzdev/Q-loader-browser](https://github.com/nzzdev/Q-loader-browser).

## Format
Currently the only type of `rendering info` supported by the Q editor preview is a JSON like this:
The Q loader browser is our reference implementation for Q loaders. Currently the only type of `rendering info` supported by the Q editor preview is a JSON like this:
```
{
"loaderConfig": {
"polyfills": ["Promise", "Object.assign"],
"loadSystemJs": "full"
},
"markup": "<p>markup applied using element.innerHTML</p>",
"scripts": [
{
"url": "url to a javascript file"
},
{
"name": "the name of a javascript file, see below 'on name and path' for more information about this"
},
{
"url": "url to a javascript file that should get loaded only once per page",
"loadOnce": true
}
],
"stylesheets": [
Expand All @@ -27,6 +35,9 @@ Currently the only type of `rendering info` supported by the Q editor preview is
]
}
```
- `loaderConfig.polyfills` is an array of features used to produce a url to the [polyfill.io](https://polyfill.io) service. The loader will merge the arrays for all Q items on a page together to produce one request to polyfill.io.

- `loaderConfig.loadSystemJs` tells the loader if it should load SystemJS. This is either `full` which loads SystemJS with support for different module types or `production` which loads a small version of SystemJS that can only load `System.register` modules.

## on name and path
In the example above you have seen the property `name` used in `scripts` and `stylesheets`. This is not quite what will be delivered by the Q server but what gets produced by the tool service. The Q server will translate the `name` to a `path` like this:
Expand Down
9 changes: 9 additions & 0 deletions docs/tool-runtime-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: tool runtime config
---

There is an object `toolRuntimeConfig` that gets passed to the tool service for every rendering info request. Before that, it can get altered at several points in the flow. The `toolRuntimeConfig` will get merged in the following order by overwriting the former in case of clashes.

1. Q server config misc.toolRuntimeConfig (use this in case you want to pass some values to all tools)
2. Q server config tools in tool.endpoint.toolRuntimeConfig (where the value is filtered with the target)
3. as a query parameter or payload object to rendering-info endpoint
Loading

0 comments on commit e22ce10

Please sign in to comment.