1
0
Fork 0
mirror of https://gitlab.com/bramw/baserow.git synced 2025-04-12 08:18:07 +00:00
bramw_baserow/web-frontend/modules/core/module.js

106 lines
3.1 KiB
JavaScript

import path from 'path'
import _ from 'lodash'
import serveStatic from 'serve-static'
import { routes } from './routes'
import head from './head'
export default function DatabaseModule(options) {
/**
* This function adds a plugin, but rather then prepending it to the list it will
* be appended.
*/
this.appendPlugin = (template) => {
this.addPlugin(template)
this.options.plugins.push(this.options.plugins.splice(0, 1)[0])
}
// Baserow must be run in universal mode.
this.options.mode = 'universal'
// Set the default head object, but override the configured head.
// @TODO if a child is a list the new children must be appended instead of overridden.
this.options.head = _.merge({}, head, this.options.head)
// Store must be true in order for the store to be injected into the context.
this.options.store = true
// Register new alias to the web-frontend directory.
this.options.alias['@baserow'] = path.resolve(__dirname, '../../')
// The core depends on these modules.
this.requireModule('@nuxtjs/axios')
this.requireModule('cookie-universal-nuxt')
this.requireModule([
'nuxt-env',
{
keys: [
{
key: 'PRIVATE_BACKEND_URL',
default: 'http://backend:8000',
},
{
key: 'PUBLIC_BACKEND_URL',
default: 'http://localhost:8000',
},
{
key: 'PUBLIC_WEB_FRONTEND_URL',
default: 'http://localhost:3000',
},
],
},
])
// Serve the static directory
// @TODO we might need to change some things here for production. (See:
// https://github.com/nuxt/nuxt.js/blob/5a6cde3ebc23f04e89c30a4196a9b7d116b6d675/
// packages/server/src/server.js)
const staticMiddleware = serveStatic(
path.resolve(__dirname, 'static'),
this.options.render.static
)
this.addServerMiddleware(staticMiddleware)
this.addLayout(path.resolve(__dirname, 'layouts/error.vue'), 'error')
this.addLayout(path.resolve(__dirname, 'layouts/app.vue'), 'app')
this.addLayout(path.resolve(__dirname, 'layouts/login.vue'), 'login')
const plugins = [
'middleware.js',
'plugin.js',
'plugins/auth.js',
'plugins/global.js',
'plugins/vuelidate.js',
]
plugins.forEach((plugin) => {
this.addPlugin({
src: path.resolve(__dirname, plugin),
})
})
// The client handler depends on environment variables so the plugin must be added
// after the nuxt-env module's plugin.
this.appendPlugin({
src: path.resolve(__dirname, 'plugins/clientHandler.js'),
})
this.extendRoutes((configRoutes) => {
// Remove all the routes created by nuxt.
let i = configRoutes.length
while (i--) {
if (configRoutes[i].component.includes('/@nuxt/')) {
configRoutes.splice(i, 1)
}
}
// Add the routes from the ./routes.js.
configRoutes.push(...routes)
})
// Add a default authentication middleware. In order to add a new middleware the
// middleware.js file has to be changed.
this.options.router.middleware.push('authentication')
// Add the main scss file which contains all the generic scss code.
this.options.css.push(path.resolve(__dirname, 'assets/scss/default.scss'))
}