aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nuxt.config.js3
-rw-r--r--src/api/structures/Server.js25
-rw-r--r--src/site/plugins/nuxt-client-init.js3
-rw-r--r--src/site/store/index.js3
4 files changed, 9 insertions, 25 deletions
diff --git a/nuxt.config.js b/nuxt.config.js
index b269998..80fbb4f 100644
--- a/nuxt.config.js
+++ b/nuxt.config.js
@@ -16,7 +16,7 @@ const clientConfig = {
};
export default {
- mode: 'spa',
+ ssr: true,
server: {
port: process.env.WEBSITE_PORT
},
@@ -66,7 +66,6 @@ export default {
'~/plugins/vue-isyourpasswordsafe',
'~/plugins/vue-timeago',
'~/plugins/vuebar',
- '~/plugins/nuxt-client-init',
'~/plugins/notifier',
'~/plugins/handler'
],
diff --git a/src/api/structures/Server.js b/src/api/structures/Server.js
index 446c621..268ba68 100644
--- a/src/api/structures/Server.js
+++ b/src/api/structures/Server.js
@@ -5,6 +5,7 @@ if (!process.env.SERVER_PORT) {
process.exit(0);
}
+const { loadNuxt, build } = require('nuxt');
const express = require('express');
const helmet = require('helmet');
const cors = require('cors');
@@ -80,25 +81,13 @@ class Server {
});
}
- serveNuxt() {
- // Serve the frontend if we are in production mode
- if (process.env.NODE_ENV === 'production') {
- this.server.use(express.static(path.join(__dirname, '../../../dist')));
+ async serveNuxt() {
+ const isProd = process.env.NODE_ENV === 'production';
+ const nuxt = await loadNuxt(isProd ? 'start' : 'dev');
+ this.server.use(nuxt.render);
+ if (!isProd) {
+ build(nuxt);
}
-
- /*
- For vue router to work with express we need this fallback.
- After all the routes are loaded and the static files handled and if the
- user is trying to access a non-mapped route we serve the website instead
- since it has routes of it's own that don't work if accessed directly
- */
- this.server.all('*', (_req, res) => {
- try {
- res.sendFile(path.join(__dirname, '../../../dist/index.html'));
- } catch (error) {
- res.json({ success: false, message: 'Something went wrong' });
- }
- });
}
createJobs() {
diff --git a/src/site/plugins/nuxt-client-init.js b/src/site/plugins/nuxt-client-init.js
deleted file mode 100644
index 4b10dcd..0000000
--- a/src/site/plugins/nuxt-client-init.js
+++ /dev/null
@@ -1,3 +0,0 @@
-export default async ctx => {
- await ctx.store.dispatch('nuxtClientInit', ctx);
-};
diff --git a/src/site/store/index.js b/src/site/store/index.js
index 94d673f..b94a336 100644
--- a/src/site/store/index.js
+++ b/src/site/store/index.js
@@ -1,9 +1,8 @@
import config from '../../../dist/config.json';
export const actions = {
- async nuxtClientInit({ commit, dispatch }) {
+ async nuxtServerInit({ commit, dispatch }) {
commit('config/set', config);
-
const cookies = this.$cookies.getAll();
if (!cookies.token) return dispatch('auth/logout');