Skip to content

Commit

Permalink
fix: support passing options through nuxtNeo property (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
rchl authored Oct 29, 2021
1 parent 083dcf1 commit 77700dc
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
11 changes: 11 additions & 0 deletions docs/content/basic-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ Create a new folder on your project, lets assume ```~/api```.
}]
]
}

// or alternatively:

{
modules: [
'nuxt-neo'
],
nuxtNeo: {
directory: __dirname + '/api'
}
}
```
Then lets create a new file, for example, ```~/api/todos.js``` and export a new class:
```js
Expand Down
11 changes: 11 additions & 0 deletions docs/content/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ Then add the module to `nuxt.config.js`:
}]
]
}

// or alternatively:

{
modules: [
'nuxt-neo'
],
nuxtNeo: {
directory: __dirname + '/api'
}
}
```


2 changes: 1 addition & 1 deletion lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const DEFAULT_MODULE_OPTIONS = {
};

export default async function NeoModule(moduleOptions) {
moduleOptions = Object.assign({}, DEFAULT_MODULE_OPTIONS, moduleOptions);
moduleOptions = Object.assign({}, DEFAULT_MODULE_OPTIONS, moduleOptions, this.options.nuxtNeo);
moduleOptions.aliasKey = /^[~|@]/g;
moduleOptions.srcDir = this.options.srcDir;
moduleOptions.directory = moduleOptions.directory.replace(moduleOptions.aliasKey, moduleOptions.srcDir);
Expand Down
18 changes: 18 additions & 0 deletions tests/api.configuration.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import test from 'ava';

/* global globalBeforeAll:readable, globalAfterAll:readable, api:readable */

test.before(globalBeforeAll({
nuxtOptions: {
nuxtNeo: {
prefix: '/api/v2',
errorHandler: '~/error_handler'
}
}
}));
test.after(globalAfterAll());

test('Test first level api (GET /api/v2/users) with options specified in nuxt config', async (t) => {
const { data } = await api.get('/users');
t.true(data.ok);
});
2 changes: 1 addition & 1 deletion tests/setup/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ global.globalBeforeAll = function ({ moduleOptions, nuxtOptions } = {}) {

// Globalize API requests
const api = axios.create({
baseURL: serverUrl(options.modules[0][1].prefix || '/api')
baseURL: serverUrl(options.modules[0][1].prefix || (options.nuxtNeo && options.nuxtNeo.prefix) || '/api')
});

// Build and create web server
Expand Down

0 comments on commit 77700dc

Please sign in to comment.