aboutsummaryrefslogtreecommitdiff
path: root/src/start.js
diff options
context:
space:
mode:
authorPitu <[email protected]>2018-09-16 00:56:25 -0300
committerPitu <[email protected]>2018-09-16 00:56:25 -0300
commit3243d85b59d299311b758233c409f942598628dd (patch)
treea2e475c0711b0cdc9f62ad6fa9861779b45d0b9d /src/start.js
parentRoutes (diff)
downloadhost.fuwn.me-3243d85b59d299311b758233c409f942598628dd.tar.xz
host.fuwn.me-3243d85b59d299311b758233c409f942598628dd.zip
First version of start script
Diffstat (limited to 'src/start.js')
-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);