Skip to content

Commit

Permalink
feat: Make API path namespace configurable (#53)
Browse files Browse the repository at this point in the history
* Make API path namespace configurable

* Refactor baseRoute to basePath
  • Loading branch information
dtslvr authored and paveltiunov committed Mar 18, 2019
1 parent 2b2d0e8 commit b074a3d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
7 changes: 4 additions & 3 deletions docs/Cube.js-Backend/@cubejs-backend-server-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ Express application.

Create an instance of `CubejsServerCore` to embed it in an `Express` application.

* `options` - options object.
* `options` - Options object.
* `dbType` - Type of your database.
* `driverFactory()` - pass function of the driver factory with your database type.
* `logger(msg, params)` - pass function for your custom logger.
* `driverFactory()` - Pass function of the driver factory with your database type.
* `logger(msg, params)` - Pass function for your custom logger.
* `schemaPath` - Path to the `schema` location. By default, it is `/schema`.
* `devServer` - Enable development server. By default, it is `true`.
* `basePath` - Path where _Cube.js_ is mounted to. By default, it is `/cubejs-api`.
* `checkAuthMiddleware` - Pass express-style middleware to check authentication. Set `req.authInfo = { u: { ...userContextObj } }` inside middleware if you want to provide `USER_CONTEXT`. [Learn more](/cube#context-variables-user-context).

```javascript
Expand Down
7 changes: 4 additions & 3 deletions packages/cubejs-api-gateway/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,11 @@ class ApiGateway {
this.adapterApi = adapterApi;
this.logger = logger;
this.checkAuthMiddleware = options.checkAuthMiddleware || this.checkAuth.bind(this);
this.basePath = options.basePath || '/cubejs-api';
}

initApp(app) {
app.get('/cubejs-api/v1/load', this.checkAuthMiddleware, (async (req, res) => {
app.get(`${this.basePath}/v1/load`, this.checkAuthMiddleware, (async (req, res) => {
try {
const query = JSON.parse(req.query.query);
this.log(req, {
Expand Down Expand Up @@ -231,7 +232,7 @@ class ApiGateway {
}
}));

app.get('/cubejs-api/v1/sql', this.checkAuthMiddleware, (async (req, res) => {
app.get(`${this.basePath}/v1/sql`, this.checkAuthMiddleware, (async (req, res) => {
try {
const query = JSON.parse(req.query.query);
const normalizedQuery = normalizeQuery(query);
Expand All @@ -244,7 +245,7 @@ class ApiGateway {
}
}));

app.get('/cubejs-api/v1/meta', this.checkAuthMiddleware, (async (req, res) => {
app.get(`${this.basePath}/v1/meta`, this.checkAuthMiddleware, (async (req, res) => {
try {
const metaConfig = await this.compilerApi.metaConfig();
const cubes = metaConfig.map(c => c.config);
Expand Down
1 change: 1 addition & 0 deletions packages/cubejs-server-core/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class CubejsServerCore {
this.compilerApi,
this.orchestratorApi,
this.logger, {
basePath: this.options.basePath,
checkAuthMiddleware: this.options.checkAuthMiddleware
}
);
Expand Down

0 comments on commit b074a3d

Please sign in to comment.