2018-09-13 10:51:20 +03:00
|
|
|
import _get from 'lodash/get'
|
2019-04-20 13:35:43 +03:00
|
|
|
import axios from 'axios'
|
2018-09-02 23:26:15 +03:00
|
|
|
import { createApp } from './app'
|
|
|
|
|
2019-04-20 13:35:43 +03:00
|
|
|
import config from '../config'
|
|
|
|
|
|
|
|
axios.defaults.baseURL = `http://localhost:${config.port}`
|
|
|
|
|
2018-09-13 10:51:20 +03:00
|
|
|
export default async context => {
|
2018-09-02 23:26:15 +03:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const { app, router, store } = createApp()
|
|
|
|
|
|
|
|
router.push(context.url)
|
2018-10-03 00:07:01 +03:00
|
|
|
router.onReady(() => {
|
2018-09-02 23:26:15 +03:00
|
|
|
const matchedComponents = router.getMatchedComponents()
|
|
|
|
|
2019-04-18 00:52:43 +03:00
|
|
|
// TODO not reject, create fallback to 404 component
|
2018-09-02 23:26:15 +03:00
|
|
|
if (!matchedComponents.length) {
|
|
|
|
return reject({
|
|
|
|
code: 404,
|
|
|
|
error: new Error('no component matched')
|
|
|
|
})
|
|
|
|
}
|
2018-10-03 00:07:01 +03:00
|
|
|
context.state = store.state
|
|
|
|
resolve(app)
|
2018-09-02 23:26:15 +03:00
|
|
|
}, reject)
|
|
|
|
})
|
|
|
|
}
|