| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 | /* global siteConfig */import Vue from 'vue'import VueRouter from 'vue-router'import VueClipboards from 'vue-clipboards'import VeeValidate from 'vee-validate'import { ApolloClient } from 'apollo-client'import { createPersistedQueryLink } from 'apollo-link-persisted-queries'import { BatchHttpLink } from 'apollo-link-batch-http'import { ApolloLink, split } from 'apollo-link'// import { createHttpLink } from 'apollo-link-http'import { WebSocketLink } from 'apollo-link-ws'import { ErrorLink } from 'apollo-link-error'import { InMemoryCache } from 'apollo-cache-inmemory'import { getMainDefinition } from 'apollo-utilities'import VueApollo from 'vue-apollo'import Vuetify from 'vuetify'import Velocity from 'velocity-animate'import Vuescroll from 'vuescroll/dist/vuescroll-native'import Hammer from 'hammerjs'import moment from 'moment'import VueMoment from 'vue-moment'import VueTour from 'vue-tour'import store from './store'import Cookies from 'js-cookie'// ====================================// Load Modules// ====================================import boot from './modules/boot'import localization from './modules/localization'// ====================================// Load Helpers// ====================================import helpers from './helpers'// ====================================// Initialize Global Vars// ====================================window.WIKI = nullwindow.boot = bootwindow.Hammer = Hammermoment.locale(siteConfig.lang)store.commit('user/REFRESH_AUTH')// ====================================// Initialize Apollo Client (GraphQL)// ====================================const graphQLEndpoint = window.location.protocol + '//' + window.location.host + '/graphql'const graphQLWSEndpoint = ((window.location.protocol === 'https:') ? 'wss:' : 'ws:') + '//' + window.location.host + '/graphql-subscriptions'const graphQLLink = ApolloLink.from([  new ErrorLink(({ graphQLErrors, networkError }) => {    if (graphQLErrors) {      graphQLErrors.map(({ message, locations, path }) =>        console.error(          `[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`        )      )      store.commit('showNotification', {        style: 'red',        message: `An expected error occured.`,        icon: 'warning'      })    }    if (networkError) {      console.error(networkError)      store.commit('showNotification', {        style: 'red',        message: `Network Error: ${networkError.message}`,        icon: 'error'      })    }  }),  // createPersistedQueryLink(),  new BatchHttpLink({    includeExtensions: true,    uri: graphQLEndpoint,    credentials: 'include',    fetch: async (uri, options) => {      // Strip __typename fields from variables      let body = JSON.parse(options.body)      body = body.map(bd => {        return ({          ...bd,          variables: JSON.parse(JSON.stringify(bd.variables), (key, value) => { return key === '__typename' ? undefined : value })        })      })      // body = {      //   ...body,      //   variables: JSON.parse(JSON.stringify(body.variables), (key, value) => { return key === '__typename' ? undefined : value })      // }      options.body = JSON.stringify(body)      // Inject authentication token      const jwtToken = Cookies.get('jwt')      if (jwtToken) {        options.headers.Authorization = `Bearer ${jwtToken}`      }      const resp = await fetch(uri, options)      // Handle renewed JWT      const newJWT = resp.headers.get('new-jwt')      if (newJWT) {        Cookies.set('jwt', newJWT, { expires: 365 })      }      return resp    }  })])const graphQLWSLink = new WebSocketLink({  uri: graphQLWSEndpoint,  options: {    reconnect: true,    lazy: true  }})window.graphQL = new ApolloClient({  link: split(({ query }) => {    const { kind, operation } = getMainDefinition(query)    return kind === 'OperationDefinition' && operation === 'subscription'  }, graphQLWSLink, graphQLLink),  cache: new InMemoryCache(),  connectToDevTools: (process.env.node_env === 'development')})// ====================================// Initialize Vue Modules// ====================================Vue.config.productionTip = falseVue.use(VueRouter)Vue.use(VueApollo)Vue.use(VueClipboards)Vue.use(localization.VueI18Next)Vue.use(helpers)Vue.use(VeeValidate, { events: '' })Vue.use(Vuetify)Vue.use(VueMoment, { moment })Vue.use(Vuescroll)Vue.use(VueTour)Vue.prototype.Velocity = Velocity// ====================================// Register Vue Components// ====================================Vue.component('admin', () => import(/* webpackChunkName: "admin" */ './components/admin.vue'))Vue.component('editor', () => import(/* webpackPrefetch: -100, webpackChunkName: "editor" */ './components/editor.vue'))Vue.component('history', () => import(/* webpackChunkName: "history" */ './components/history.vue'))Vue.component('page-source', () => import(/* webpackChunkName: "source" */ './components/source.vue'))Vue.component('loader', () => import(/* webpackPrefetch: true, webpackChunkName: "ui-extra" */ './components/common/loader.vue'))Vue.component('login', () => import(/* webpackPrefetch: true, webpackChunkName: "login" */ './components/login.vue'))Vue.component('nav-header', () => import(/* webpackMode: "eager" */ './components/common/nav-header.vue'))Vue.component('page-selector', () => import(/* webpackPrefetch: true, webpackChunkName: "ui-extra" */ './components/common/page-selector.vue'))Vue.component('profile', () => import(/* webpackChunkName: "profile" */ './components/profile.vue'))Vue.component('register', () => import(/* webpackChunkName: "register" */ './components/register.vue'))Vue.component('v-card-chin', () => import(/* webpackPrefetch: true, webpackChunkName: "ui-extra" */ './components/common/v-card-chin.vue'))Vue.component('search-results', () => import(/* webpackPrefetch: true, webpackChunkName: "ui-extra" */ './components/common/search-results.vue'))Vue.component('nav-footer', () => import(/* webpackChunkName: "theme-page"  */ './themes/' + process.env.CURRENT_THEME + '/components/nav-footer.vue'))Vue.component('nav-sidebar', () => import(/* webpackChunkName: "theme-page" */ './themes/' + process.env.CURRENT_THEME + '/components/nav-sidebar.vue'))Vue.component('page', () => import(/* webpackChunkName: "theme-page" */ './themes/' + process.env.CURRENT_THEME + '/components/page.vue'))let bootstrap = () => {  // ====================================  // Notifications  // ====================================  window.addEventListener('beforeunload', () => {    store.dispatch('startLoading')  })  const apolloProvider = new VueApollo({    defaultClient: window.graphQL  })  // ====================================  // Bootstrap Vue  // ====================================  const i18n = localization.init()  window.WIKI = new Vue({    el: '#root',    components: {},    mixins: [helpers],    apolloProvider,    store,    i18n  })  // ----------------------------------  // Dispatch boot ready  // ----------------------------------  window.boot.notify('vue')  // ====================================  // Load theme-specific code  // ====================================  import(/* webpackChunkName: "theme-page"  */ './themes/' + process.env.CURRENT_THEME + '/js/app.js')  // ====================================  // Load Icons  // ====================================  // import(/* webpackChunkName: "icons" */ './svg/icons.svg').then(icons => {  //   document.body.insertAdjacentHTML('beforeend', icons.default)  // })}window.boot.onDOMReady(bootstrap)
 |