Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

axios complains about adapter field in config object #79

Open
ismanf opened this issue Dec 17, 2018 · 1 comment
Open

axios complains about adapter field in config object #79

ismanf opened this issue Dec 17, 2018 · 1 comment

Comments

@ismanf
Copy link

ismanf commented Dec 17, 2018

This code example on js-data-http guid simply does not work for me:

import { Container } from 'js-data';
import { HttpAdapter } from 'js-data-http-node';

const httpAdapter = new HttpAdapter({
	basePath: 'https://mydomain.com'
});
const store = new Container();

store.registerAdapter('http', httpAdapter, { 'default': true });

store.defineMapper('school');
store.defineMapper('student');

// GET /school/1
store.find('school', 1).then((school) => {
  console.log('school');
});

It throws error:

TypeError: adapter is not a function at dispatchRequest (/Users/ismail.niftaliev/Documents/demo/dummy_server/node_modules/axios/lib/core/dispatchRequest.js:59:10) at <anonymous> at process._tickCallback (internal/process/next_tick.js:189:7) at Function.Module.runMain (module.js:696:11) at startup (bootstrap_node.js:204:16) at bootstrap_node.js:625:3

The problem is in config object which you send to axios
you set adapter: 'http'
and axios first checks if config has an adapter then uses it if not uses default adapter and then calls it as a function, so while you set a string as a value for adapter it makes axios crazy.

Thanks!

@ismanf
Copy link
Author

ismanf commented Dec 17, 2018

My solution was:

const httpAdapter = new HttpAdapter({
    basePath: '[some url]',
    http: (config) => {
        // axios will use it's default adapter
        config.adapter = null;
        return axios(config);
    }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant