aboutsummaryrefslogtreecommitdiff
path: root/vnext
diff options
context:
space:
mode:
Diffstat (limited to 'vnext')
-rw-r--r--vnext/config/default.json9
-rw-r--r--vnext/server/bootstrap.js11
-rw-r--r--vnext/server/index.js5
-rw-r--r--vnext/server/middleware/renderer.js5
4 files changed, 28 insertions, 2 deletions
diff --git a/vnext/config/default.json b/vnext/config/default.json
new file mode 100644
index 000000000..ae52a7173
--- /dev/null
+++ b/vnext/config/default.json
@@ -0,0 +1,9 @@
+{
+ "service": {
+ "application": "",
+ "static_root": "dist",
+ "sape": {
+ "token": ""
+ }
+ }
+} \ No newline at end of file
diff --git a/vnext/server/bootstrap.js b/vnext/server/bootstrap.js
new file mode 100644
index 000000000..0f920886f
--- /dev/null
+++ b/vnext/server/bootstrap.js
@@ -0,0 +1,11 @@
+require('ignore-styles');
+require('url-loader');
+require('file-loader');
+require('@babel/register')({
+ ignore: [/(node_modules)/],
+ presets: [
+ '@babel/preset-env',
+ ['@babel/preset-react', { 'runtime': 'automatic' }]
+ ]
+});
+require('./index');
diff --git a/vnext/server/index.js b/vnext/server/index.js
index f9a432b90..729f05d65 100644
--- a/vnext/server/index.js
+++ b/vnext/server/index.js
@@ -1,4 +1,5 @@
import express from 'express';
+import config from 'config';
// we'll talk about this in a minute:
import serverRenderer from './middleware/renderer';
@@ -18,9 +19,11 @@ router.get('/api/oembed', oembed);
router.get('/api/urlexpand', urlExpand);
router.use('^/$', serverRenderer);
+const STATIC_ROOT = config.get('service.static_root') || path.resolve(__dirname, 'dist');
+
// other static resources should just be served as they are
router.use(express.static(
- path.resolve(__dirname),
+ STATIC_ROOT,
{ maxAge: '30d' },
));
diff --git a/vnext/server/middleware/renderer.js b/vnext/server/middleware/renderer.js
index 4223d7f2a..a4b745f8c 100644
--- a/vnext/server/middleware/renderer.js
+++ b/vnext/server/middleware/renderer.js
@@ -1,5 +1,6 @@
import * as ReactDOMServer from 'react-dom/server';
import cookie from 'cookie';
+import config from 'config';
// import our main App component
import App from '../../src/App';
@@ -20,10 +21,12 @@ function toBinary(string) {
return Buffer.from(String.fromCharCode(...new Uint8Array(codeUnits.buffer))).toString('base64');
}
+const STATIC_ROOT = config.get('service.static_root') || path.resolve(__dirname, 'dist');
+
const serverRenderer = async (req, res) => {
// point to the html file created by CRA's build tool
- const filePath = path.resolve('index.html');
+ const filePath = path.resolve(STATIC_ROOT, 'index.html');
// links
const cookies = cookie.parse(req.headers.cookie || '');