T
T
toropchin2020-02-23 21:23:31
Vue.js
toropchin, 2020-02-23 21:23:31

Why doesn't axios see the http adapter when running under node?

I'm struggling with SSR in laravel + vue.js + axios. The latter does not see the http adapter. When sending a get request, the promise is rejected with an error:

TypeError: adapter is not a function at dispatchRequest (/Users/vladimir/Programming/GR/lawsystem.test/storage/app/ssr/675059bc8c1babf0be6d4ed5102e69a9.js:1058:10) TypeError: adapter is not a function at dispatchRequest (/Users/vladimir/Programming/GR/lawsystem.test/storage/app/ssr/675059bc8c1babf0be6d4ed5102e69a9.js:1058:10) at async Promise.all (index 0) "

The code is run on the side of node. For SSR I use this package here https://github.com/spatie/laravel-server-side-rendering
webpack config:
const mix = require('laravel-mix');

mix.js('resources/js/CustomerPortal/app-server.js', 'public/js/customer-portal');
mix.webpackConfig({
    target: 'node',
});


Code that works with axios:

import axios from 'axios'
export default {
    getServices() {
        return axios.get('https://lawsystem.grani-riska.ru/api/services/get',
        ).then(response => {
            return response;
        }).catch(error => {
            console.log(error); //Здесь я ловлю ошибку
        })
    },
}


I call the code above from the component:
import ServicesSidebarComponent from "./Sidebar";
    import ServiceService from "../../../Service/services/ServiceService";

    export default {
        name: "ServicesComponent",
        components: {ServicesSidebarComponent},
        data() {
            return {
                services: [
                    {
                        id: 0,
                        name: '',
                        description: '',
                        price: ''
                    }
                ],
            }
        },
        serverPrefetch() {
            return this.getServices();
        },
        created() {
            this.reset();
            this.getServices();
        },
        methods: {
            reset() {
                this.services = [];
            },
            getServices() {
                // Здесь вызываю вышеуказанный метод.
                return ServiceService.getServices().then(services => {
                    this.services = services;
                });
            }
        }
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Sviridov, 2020-02-24
@dimuska139

Are you sure it's the ssr? Try to make a test script with Axios of the same version and pull the URL https://lawsystem.grani-riska.ru/api/services/get.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question