aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/start.js60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/start.js b/src/start.js
new file mode 100644
index 0000000..2ce4bc9
--- /dev/null
+++ b/src/start.js
@@ -0,0 +1,60 @@
+const Backend = require('./api/structures/Server');
+const express = require('express');
+const compression = require('compression');
+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 reamConfig = require('../../ream.config');
+
+function startProduction() {
+ startAPI();
+ startSite();
+}
+
+function startAPI() {
+ new Backend().start();
+ // const backend = new Backend().start();
+ // backend.start();
+}
+
+function startSite() {
+ // console.log(reamConfig);
+ // console.log();
+ const server = express();
+ const app = ream({
+ // The path join below prints X:\lolisafe2.2\src\site\index.js which is correct
+ entry: path.join(__dirname, 'site', 'index.js'),
+ html: path.join(__dirname, 'site', 'index.html'),
+ // entry: './site/index.js',
+ // html: './site/index.html',
+ dev
+ });
+
+ // console.log(app);
+
+ app.getRequestHandler().then(handler => {
+ server.use(compression());
+ /*
+ JUST TEMPORARY FOR LOCAL DEVELOPMENT, LETS SERVE THE UPLOADS FOLDER
+ */
+ /*
+ if (config.serveFilesWithNode) {
+ server.use('/', express.static(`./${config.uploads.uploadFolder}`));
+ }
+ */
+ server.get('*', handler);
+ server.listen(config.server.ports.frontend, error => {
+ if (error) log.error(error);
+ });
+ });
+
+ app.on('renderer-ready', () => log.info(`> Frontend ready and listening on port ${config.server.ports.frontend}`));
+}
+
+const args = process.argv[2];
+if (!args) startProduction();
+else if (args === 'api') startAPI();
+else if (args === 'site') startSite();
+else process.exit(0);