aboutsummaryrefslogtreecommitdiff
path: root/src/start.js
diff options
context:
space:
mode:
authorPitu <[email protected]>2018-09-19 04:45:50 -0300
committerPitu <[email protected]>2018-09-19 04:45:50 -0300
commit430af8306b1ab17e59a6dabf8f65ab816d28695d (patch)
tree975814e80919cc7b8c5d820080a30def32a371ea /src/start.js
parentSome adjustements to public album view (diff)
downloadhost.fuwn.me-430af8306b1ab17e59a6dabf8f65ab816d28695d.tar.xz
host.fuwn.me-430af8306b1ab17e59a6dabf8f65ab816d28695d.zip
Switch to Nuxt.js
Diffstat (limited to 'src/start.js')
-rw-r--r--src/start.js86
1 files changed, 83 insertions, 3 deletions
diff --git a/src/start.js b/src/start.js
index 705da12..f516ad6 100644
--- a/src/start.js
+++ b/src/start.js
@@ -1,23 +1,103 @@
const Backend = require('./api/structures/Server');
const express = require('express');
const compression = require('compression');
-const ream = require('ream');
+// const ream = require('ream');
const config = require('../config');
const path = require('path');
const log = require('./api/utils/Log');
const dev = process.env.NODE_ENV !== 'production';
const oneliner = require('one-liner');
const jetpack = require('fs-jetpack');
+// const { Nuxt, Builder } = require('nuxt-edge');
+// const nuxtConfig = require('./nuxt/nuxt.config.js');
function startProduction() {
startAPI();
- startSite();
+ // startSite();
+ // startNuxt();
}
function startAPI() {
+ writeFrontendConfig();
new Backend().start();
}
+async function startNuxt() {
+ /*
+ Make sure the frontend has enough data to prepare the service
+ */
+ writeFrontendConfig();
+
+ /*
+ Starting Nuxt's custom server powered by express
+ */
+
+ const app = express();
+
+ /*
+ Instantiate Nuxt.js
+ */
+ nuxtConfig.dev = true;
+ const nuxt = new Nuxt(nuxtConfig);
+
+ /*
+ Start the server or build it if we're on dev mode
+ */
+
+ if (nuxtConfig.dev) {
+ try {
+ await new Builder(nuxt).build();
+ } catch (error) {
+ log.error(error);
+ process.exit(1);
+ }
+ }
+
+ /*
+ Render every route with Nuxt.js
+ */
+ app.use(nuxt.render);
+
+ /*
+ Start the server and listen to the configured port
+ */
+ app.listen(config.server.ports.frontend, '127.0.0.1');
+ log.info(`> Frontend ready and listening on port ${config.server.ports.frontend}`);
+
+ /*
+ Starting Nuxt's custom server powered by express
+ */
+ /*
+ const app = express();
+ app.set('port', config.server.ports.frontend);
+
+ // Configure dev enviroment
+ nuxtConfig.dev = dev;
+
+ // Init Nuxt.js
+ const nuxt = new Nuxt(nuxtConfig);
+
+ // Build only in dev mode
+ if (nuxtConfig.dev) {
+ const builder = new Builder(nuxt);
+ await builder.build();
+ }
+
+ // Give nuxt middleware to express
+ app.use(nuxt.render);
+
+ if (config.serveFilesWithNode) {
+ app.use('/', express.static(`./${config.uploads.uploadFolder}`));
+ }
+
+ // Listen the server
+ app.listen(config.server.ports.frontend, '127.0.0.1');
+ app.on('renderer-ready', () => log.info(`> Frontend ready and listening on port ${config.server.ports.frontend}`));
+ // log.success(`> Frontend ready and listening on port ${config.server.ports.frontend}`);
+ // console.log(`Server listening on http://${host}:${port}`); // eslint-disable-line no-console
+ */
+}
+
function startSite() {
/*
Make sure the frontend has enough data to prepare the service
@@ -74,5 +154,5 @@ function writeFrontendConfig() {
const args = process.argv[2];
if (!args) startProduction();
else if (args === 'api') startAPI();
-else if (args === 'site') startSite();
+else if (args === 'site') startNuxt();
else process.exit(0);