diff --git a/docs/content/basic-usage.md b/docs/content/basic-usage.md index 57af8af..929f535 100644 --- a/docs/content/basic-usage.md +++ b/docs/content/basic-usage.md @@ -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 diff --git a/docs/content/getting-started.md b/docs/content/getting-started.md index c852187..fd148f7 100644 --- a/docs/content/getting-started.md +++ b/docs/content/getting-started.md @@ -20,6 +20,17 @@ Then add the module to `nuxt.config.js`: }] ] } + +// or alternatively: + +{ + modules: [ + 'nuxt-neo' + ], + nuxtNeo: { + directory: __dirname + '/api' + } +} ``` diff --git a/lib/module.js b/lib/module.js index 4e77327..502ea91 100755 --- a/lib/module.js +++ b/lib/module.js @@ -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); diff --git a/tests/api.configuration.test.js b/tests/api.configuration.test.js new file mode 100644 index 0000000..6e92f88 --- /dev/null +++ b/tests/api.configuration.test.js @@ -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); +}); diff --git a/tests/setup/global.js b/tests/setup/global.js index 8d8abb8..78cf5ef 100755 --- a/tests/setup/global.js +++ b/tests/setup/global.js @@ -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