You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
5.7 KiB

  1. /* global siteConfig */
  2. import Vue from 'vue'
  3. import VueRouter from 'vue-router'
  4. import VueClipboards from 'vue-clipboards'
  5. import VueSimpleBreakpoints from 'vue-simple-breakpoints'
  6. import VeeValidate from 'vee-validate'
  7. import { ApolloClient } from 'apollo-client'
  8. import { createPersistedQueryLink } from 'apollo-link-persisted-queries'
  9. // import { BatchHttpLink } from 'apollo-link-batch-http'
  10. import { split } from 'apollo-link'
  11. import { createHttpLink } from 'apollo-link-http'
  12. import { WebSocketLink } from 'apollo-link-ws'
  13. import { InMemoryCache } from 'apollo-cache-inmemory'
  14. import { getMainDefinition } from 'apollo-utilities'
  15. import VueApollo from 'vue-apollo'
  16. import Vuetify from 'vuetify'
  17. import Velocity from 'velocity-animate'
  18. import Hammer from 'hammerjs'
  19. import moment from 'moment'
  20. import VueMoment from 'vue-moment'
  21. import VueTour from 'vue-tour'
  22. import VueTreeNavigation from 'vue-tree-navigation'
  23. import store from './store'
  24. // ====================================
  25. // Load Modules
  26. // ====================================
  27. import boot from './modules/boot'
  28. import localization from './modules/localization'
  29. // ====================================
  30. // Load Helpers
  31. // ====================================
  32. import helpers from './helpers'
  33. // ====================================
  34. // Initialize Global Vars
  35. // ====================================
  36. window.WIKI = null
  37. window.boot = boot
  38. window.Hammer = Hammer
  39. moment.locale(siteConfig.lang)
  40. // ====================================
  41. // Initialize Apollo Client (GraphQL)
  42. // ====================================
  43. const graphQLEndpoint = window.location.protocol + '//' + window.location.host + '/graphql'
  44. const graphQLWSEndpoint = ((window.location.protocol === 'https:') ? 'wss:' : 'ws:') + '//' + window.location.host + '/graphql-subscriptions'
  45. const graphQLLink = createPersistedQueryLink().concat(
  46. createHttpLink({
  47. includeExtensions: true,
  48. uri: graphQLEndpoint,
  49. credentials: 'include',
  50. fetch: (uri, options) => {
  51. // Strip __typename fields from variables
  52. let body = JSON.parse(options.body)
  53. // body = body.map(bd => {
  54. // return ({
  55. // ...bd,
  56. // variables: JSON.parse(JSON.stringify(bd.variables), (key, value) => { return key === '__typename' ? undefined : value })
  57. // })
  58. // })
  59. body = {
  60. ...body,
  61. variables: JSON.parse(JSON.stringify(body.variables), (key, value) => { return key === '__typename' ? undefined : value })
  62. }
  63. options.body = JSON.stringify(body)
  64. // Inject authentication token
  65. options.headers.Authorization = `Bearer TODO`
  66. return fetch(uri, options)
  67. }
  68. })
  69. )
  70. const graphQLWSLink = new WebSocketLink({
  71. uri: graphQLWSEndpoint,
  72. options: {
  73. reconnect: true,
  74. lazy: true
  75. }
  76. })
  77. window.graphQL = new ApolloClient({
  78. link: split(({ query }) => {
  79. const { kind, operation } = getMainDefinition(query)
  80. return kind === 'OperationDefinition' && operation === 'subscription'
  81. }, graphQLWSLink, graphQLLink),
  82. cache: new InMemoryCache(),
  83. connectToDevTools: (process.env.node_env === 'development')
  84. })
  85. // ====================================
  86. // Initialize Vue Modules
  87. // ====================================
  88. Vue.config.productionTip = false
  89. Vue.use(VueRouter)
  90. Vue.use(VueApollo)
  91. Vue.use(VueClipboards)
  92. Vue.use(VueSimpleBreakpoints)
  93. Vue.use(localization.VueI18Next)
  94. Vue.use(helpers)
  95. Vue.use(VeeValidate, { events: '' })
  96. Vue.use(Vuetify)
  97. Vue.use(VueMoment, { moment })
  98. Vue.use(VueTour)
  99. Vue.use(VueTreeNavigation)
  100. Vue.prototype.Velocity = Velocity
  101. // ====================================
  102. // Register Vue Components
  103. // ====================================
  104. Vue.component('admin', () => import(/* webpackChunkName: "admin" */ './components/admin.vue'))
  105. Vue.component('editor', () => import(/* webpackPrefetch: -100, webpackChunkName: "editor" */ './components/editor.vue'))
  106. Vue.component('login', () => import(/* webpackPrefetch: true, webpackChunkName: "login" */ './components/login.vue'))
  107. Vue.component('nav-footer', () => import(/* webpackMode: "eager" */ './components/common/nav-footer.vue'))
  108. Vue.component('nav-header', () => import(/* webpackMode: "eager" */ './components/common/nav-header.vue'))
  109. Vue.component('nav-sidebar', () => import(/* webpackMode: "eager" */ './components/common/nav-sidebar.vue'))
  110. Vue.component('page', () => import(/* webpackChunkName: "theme-page" */ './themes/' + process.env.CURRENT_THEME + '/components/app.vue'))
  111. Vue.component('page-selector', () => import(/* webpackPrefetch: true, webpackChunkName: "ui-extra" */ './components/common/page-selector.vue'))
  112. Vue.component('profile', () => import(/* webpackChunkName: "profile" */ './components/profile.vue'))
  113. Vue.component('v-card-chin', () => import(/* webpackPrefetch: true, webpackChunkName: "ui-extra" */ './components/common/v-card-chin.vue'))
  114. let bootstrap = () => {
  115. // ====================================
  116. // Notifications
  117. // ====================================
  118. window.addEventListener('beforeunload', () => {
  119. store.dispatch('startLoading')
  120. })
  121. const apolloProvider = new VueApollo({
  122. defaultClient: window.graphQL
  123. })
  124. // ====================================
  125. // Bootstrap Vue
  126. // ====================================
  127. const i18n = localization.init()
  128. window.WIKI = new Vue({
  129. el: '#root',
  130. components: {},
  131. mixins: [helpers],
  132. apolloProvider,
  133. store,
  134. i18n
  135. })
  136. // ----------------------------------
  137. // Dispatch boot ready
  138. // ----------------------------------
  139. window.boot.notify('vue')
  140. // ====================================
  141. // Load Icons
  142. // ====================================
  143. // import(/* webpackChunkName: "icons" */ './svg/icons.svg').then(icons => {
  144. // document.body.insertAdjacentHTML('beforeend', icons.default)
  145. // })
  146. }
  147. window.boot.onDOMReady(bootstrap)