fix: pulling config from the db during build process

This commit is contained in:
Pitu 2021-06-20 21:16:56 +09:00
parent 270b7acd4c
commit 1c463ea81e
1 changed files with 82 additions and 72 deletions

View File

@ -3,80 +3,90 @@ import autoprefixer from 'autoprefixer';
const Util = require('./src/api/utils/Util'); const Util = require('./src/api/utils/Util');
export default { export default async () => {
ssr: true, /*
srcDir: 'src/site/', FIXME:
head: { Since Util.config is not populated during production env because it needs to grab the values from the db
title: Util.config.serviceName, we need to use this hack to populate it before we can access the properties without await like we do in the export below.
titleTemplate: `%s | ${Util.config.serviceName}`, This will be solved once the TypeScript rewrite is complete as we can can simply pass a config object to express
// TODO: Add the directory with pictures for favicon and stuff and build from there, but for now the build needs to be triggered before the API is started.
meta: [ */
{ charset: 'utf-8' }, await Util.config;
{ name: 'viewport', content: 'width=device-width, initial-scale=1' }, return {
{ hid: 'theme-color', name: 'theme-color', content: `${Util.config.metaThemeColor}` }, ssr: true,
{ hid: 'description', name: 'description', content: `${Util.config.metaDescription}` }, srcDir: 'src/site/',
{ hid: 'keywords', name: 'keywords', content: `${Util.config.metaKeywords}` }, head: {
{ title: Util.config.serviceName,
hid: 'apple-mobile-web-app-title', titleTemplate: `%s | ${Util.config.serviceName}`,
name: 'apple-mobile-web-app-title', // TODO: Add the directory with pictures for favicon and stuff
content: `${Util.config.serviceName}` meta: [
}, { charset: 'utf-8' },
{ hid: 'application-name', name: 'application-name', content: `${Util.config.serviceName}` }, { name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ hid: 'twitter:card', name: 'twitter:card', content: 'summary' }, { hid: 'theme-color', name: 'theme-color', content: `${Util.config.metaThemeColor}` },
{ hid: 'twitter:site', name: 'twitter:site', content: `${Util.config.metaTwitterHandle}` }, { hid: 'description', name: 'description', content: `${Util.config.metaDescription}` },
{ hid: 'twitter:creator', name: 'twitter:creator', content: `${Util.config.metaTwitterHandle}` }, { hid: 'keywords', name: 'keywords', content: `${Util.config.metaKeywords}` },
{ hid: 'twitter:title', name: 'twitter:title', content: `${Util.config.serviceName}` }, {
{ hid: 'twitter:description', name: 'twitter:description', content: `${Util.config.metaDescription}` }, hid: 'apple-mobile-web-app-title',
{ hid: 'twitter:image', name: 'twitter:image', content: `/logo.png` }, name: 'apple-mobile-web-app-title',
{ hid: 'og:url', property: 'og:url', content: `/` }, content: `${Util.config.serviceName}`
{ hid: 'og:type', property: 'og:type', content: 'website' }, },
{ hid: 'og:title', property: 'og:title', content: `${Util.config.serviceName}` }, { hid: 'application-name', name: 'application-name', content: `${Util.config.serviceName}` },
{ hid: 'og:description', property: 'og:description', content: `${Util.config.metaDescription}` }, { hid: 'twitter:card', name: 'twitter:card', content: 'summary' },
{ hid: 'og:image', property: 'og:image', content: `/logo.png` }, { hid: 'twitter:site', name: 'twitter:site', content: `${Util.config.metaTwitterHandle}` },
{ hid: 'og:image:secure_url', property: 'og:image:secure_url', content: `/logo.png` }, { hid: 'twitter:creator', name: 'twitter:creator', content: `${Util.config.metaTwitterHandle}` },
{ hid: 'og:site_name', property: 'og:site_name', content: `${Util.config.serviceName}` } { hid: 'twitter:title', name: 'twitter:title', content: `${Util.config.serviceName}` },
], { hid: 'twitter:description', name: 'twitter:description', content: `${Util.config.metaDescription}` },
link: [ { hid: 'twitter:image', name: 'twitter:image', content: `/logo.png` },
{ rel: 'stylesheet', href: 'https://fonts.googleapis.com/css?family=Nunito:300,400,600,700' }, { hid: 'og:url', property: 'og:url', content: `/` },
{ hid: 'og:type', property: 'og:type', content: 'website' },
{ hid: 'og:title', property: 'og:title', content: `${Util.config.serviceName}` },
{ hid: 'og:description', property: 'og:description', content: `${Util.config.metaDescription}` },
{ hid: 'og:image', property: 'og:image', content: `/logo.png` },
{ hid: 'og:image:secure_url', property: 'og:image:secure_url', content: `/logo.png` },
{ hid: 'og:site_name', property: 'og:site_name', content: `${Util.config.serviceName}` }
],
link: [
{ rel: 'stylesheet', href: 'https://fonts.googleapis.com/css?family=Nunito:300,400,600,700' },
// This one is a pain in the ass to make it customizable, so you should edit it manually // This one is a pain in the ass to make it customizable, so you should edit it manually
{ type: 'application/json+oembed', href: `/oembed.json` } { type: 'application/json+oembed', href: `/oembed.json` }
] ]
},
plugins: [
'~/plugins/axios',
'~/plugins/buefy',
'~/plugins/v-clipboard',
'~/plugins/vue-isyourpasswordsafe',
'~/plugins/vue-timeago',
'~/plugins/vuebar',
'~/plugins/notifier',
'~/plugins/handler'
],
css: [],
modules: ['@nuxtjs/axios', 'cookie-universal-nuxt'],
router: {
linkActiveClass: 'is-active',
linkExactActiveClass: 'is-active'
},
env: {
development: process.env.NODE_ENV !== 'production'
},
axios: {
baseURL: `${process.env.NODE_ENV === 'production' ? process.env.DOMAIN : 'http://localhost:5000'}/api`
},
build: {
extractCSS: process.env.NODE_ENV === 'production',
postcss: {
preset: {
autoprefixer
}
}, },
extend(config, { isDev }) { plugins: [
// Extend only webpack config for client-bundle '~/plugins/axios',
if (isDev) { '~/plugins/buefy',
config.devtool = 'source-map'; '~/plugins/v-clipboard',
'~/plugins/vue-isyourpasswordsafe',
'~/plugins/vue-timeago',
'~/plugins/vuebar',
'~/plugins/notifier',
'~/plugins/handler'
],
css: [],
modules: ['@nuxtjs/axios', 'cookie-universal-nuxt'],
router: {
linkActiveClass: 'is-active',
linkExactActiveClass: 'is-active'
},
env: {
development: process.env.NODE_ENV !== 'production'
},
axios: {
baseURL: `${process.env.NODE_ENV === 'production' ? process.env.DOMAIN : 'http://localhost:5000'}/api`
},
build: {
extractCSS: process.env.NODE_ENV === 'production',
postcss: {
preset: {
autoprefixer
}
},
extend(config, { isDev }) {
// Extend only webpack config for client-bundle
if (isDev) {
config.devtool = 'source-map';
}
} }
} }
} };
}; };