entry-server.js
961 Bytes
import {createApp} from './app';
import {
SET_ENV
} from 'store/yoho/types';
const {app, router, store} = createApp();
export default context => {
return new Promise((resolve, reject) => {
const {url} = context;
const route = router.resolve(url).route;
if (url !== route.fullPath && url !== route.redirectedFrom) {
reject({url: route.fullPath});
}
store.commit(SET_ENV, context.env);
router.push(url);
router.onReady(() => {
const matched = router.getMatchedComponents();
if (!matched.length) {
reject({code: 404});
}
Promise.all(matched.map(({asyncData}) =>
asyncData && asyncData({store, router: router.currentRoute})))
.then(() => {
context.state = store.state;
resolve(app);
}).catch(reject);
}, reject);
});
};