-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
382 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# RESTBase wikimedia example config | ||
default_project: &default_project | ||
x-modules: | ||
- spec: | ||
paths: | ||
/{api:v1}: | ||
x-modules: | ||
- spec: | ||
paths: | ||
/key_value: | ||
x-modules: | ||
- path: sys/key_value.js | ||
/page_revisions: | ||
# We need to forward cookie to the API | ||
x-route-filters: | ||
- path: ./lib/mediawiki_auth_filter.js | ||
x-modules: | ||
- path: sys/page_revisions.js | ||
/{api:sys}: | ||
x-modules: | ||
- spec: | ||
paths: | ||
/table: | ||
x-modules: | ||
- path: sys/table.js | ||
options: | ||
conf: | ||
backend: '{env(RB_TEST_BACKEND, sqlite)}' | ||
hosts: [localhost] | ||
keyspace: system | ||
username: cassandra | ||
password: cassandra | ||
defaultConsistency: one # or 'localQuorum' for production | ||
storage_groups: | ||
- name: test.group.local | ||
domains: /./ | ||
dbname: test.db.sqlite3 # ignored in cassandra, but useful in SQLite testing | ||
/action: | ||
x-modules: | ||
- path: sys/action.js | ||
options: | ||
apiUriTemplate: "{{'https://{domain}/w/api.php'}}" | ||
baseUriTemplate: "{{'https://{domain}/api/rest_v1'}}" | ||
|
||
|
||
# The root of the spec tree. Domains tend to share specs by referencing them | ||
# using YAML references. | ||
spec_root: &spec_root | ||
title: "The RESTBase Storage Service" | ||
x-sub-request-filters: | ||
- type: default | ||
name: http | ||
options: | ||
allow: | ||
- pattern: /^https?:\/\/[a-zA-Z0-9\.]+\/w\/api\.php/ | ||
forward_headers: true | ||
paths: | ||
/{domain}: *default_project | ||
|
||
# Finally, a standard service-runner config. | ||
info: | ||
name: restbase | ||
|
||
services: | ||
- name: restbase | ||
module: hyperswitch | ||
conf: | ||
port: 7232 | ||
spec: *spec_root | ||
salt: secret | ||
default_page_size: 125 | ||
user_agent: RESTBase | ||
ui_name: RESTBase | ||
ui_url: https://www.mediawiki.org/wiki/RESTBase | ||
ui_title: RESTBase docs | ||
|
||
logging: | ||
name: restbase | ||
level: error | ||
streams: | ||
- type: stdout | ||
|
||
#metrics: | ||
# type: statsd | ||
# host: localhost | ||
# port: 8125 | ||
# batch: true | ||
|
||
num_workers: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
'use strict'; | ||
|
||
const Template = require('hyperswitch').Template; | ||
|
||
module.exports = (options) => { | ||
options.backend_host_template = options.backend_host_template || '/{domain}/sys/legacy'; | ||
const backendURITemplate = new Template({ | ||
uri: `${options.backend_host_template}/{{path}}` | ||
}); | ||
return { | ||
spec: { | ||
paths: { | ||
'/{+path}': { | ||
all: { | ||
operationId: 'proxy' | ||
} | ||
} | ||
} | ||
}, | ||
operations: { | ||
proxy: (hyper, req) => { | ||
// Add the proxied module name to the path. | ||
// The proxy is mounted at paths like `/sys/key_value`. Here | ||
// out of a request path we want to find out the name of the module | ||
// that is being proxied (key_value) from the example and add it | ||
// to the proxy target path. | ||
const modName = req.uri.path[req.uri.path.indexOf('sys') + 1]; | ||
req.params.path = `${modName}/${req.params.path}`; | ||
return hyper.request({ | ||
method: req.method, | ||
uri: backendURITemplate.expand({ request: req }).uri, | ||
headers: req.headers, | ||
body: req.body, | ||
query: req.query | ||
}) | ||
.then((res) => { | ||
// We are slowly switching to storing data as binary blobs | ||
// in the storage component. When running multi-process, | ||
// the storage component will return the appropriate | ||
// content-type and deserializing the response will | ||
// happen internally in preq. However, when running | ||
// single process, preq is not involved, so for consistency | ||
// we need to manually deserialize the returned blob. | ||
if (res && | ||
res.headers && | ||
res.headers['content-type'] && | ||
res.headers['content-type'].startsWith('application/json') && | ||
Buffer.isBuffer(res.body)) { | ||
res.body = JSON.parse(res.body.toString('utf8')); | ||
} | ||
return res; | ||
}); | ||
} | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.