A
A
Alexander Florenko2019-06-26 01:14:39
Vue.js
Alexander Florenko, 2019-06-26 01:14:39

Why is the Vue app crashing?

The load test on the server has begun. If at this moment the client accesses the api, then the Vue + SSR application server crashes.
The request is executed in asyncData

async asyncData({store}) {
    return Promise.all([
        store.dispatch('func1'),
        store.dispatch('func2'),
        store.dispatch('func3'),
        store.dispatch('func4',
    ]).then(values => {
        return values;
    });
},

If you use await func() instead of Promise.all() then everything is ok.
At the time of the crash, any (postman, for example) requests to api return a `504 Gateway Timeout` error.
There is nothing in the application server console (
Until you restart the application server.
What could be the reason?
Configs vue + ssr
server.js
entry-server.js
entry-client.js

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniil Bratukhin, 2019-06-26
@dantothefuture

Without delving into the implementation, usually they return from asyncData Promise<Object|void>, and you have Promise<Array>. Yes, an array is also an object, but Javascript's ways are inscrutable. This array is then passed to the router's next function in entry-client.js:16, which shouldn't be able to handle it either, and so on. etc.
One way or another, if asyncData is used only to fill the store, there is no point in passing anything to the resolve promise:

async asyncData ({ store }) {
  await Promise.all([
    store.dispatch('func1'),
    store.dispatch('func2'),
    store.dispatch('func3'),
    store.dispatch('func4')
  ])
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question