aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2022-01-12 09:19:47 +0000
committers-ol <s+removethis@s-ol.nu>2022-01-12 09:33:13 +0000
commit7bcd1e44d3f78a4120be295f6a31b57917cee563 (patch)
tree97876551f64f7eb0fb78b963d985bc1d1580d7dc
parenthandle errors while loading more gracefully (diff)
downloadfedidag-7bcd1e44d3f78a4120be295f6a31b57917cee563.tar.gz
fedidag-7bcd1e44d3f78a4120be295f6a31b57917cee563.zip
add instructions and commands for local CORS proxy
-rw-r--r--README.md12
-rw-r--r--cors.js9
-rw-r--r--package.json5
-rw-r--r--src/index.js6
-rw-r--r--webpack.config.js2
5 files changed, 28 insertions, 6 deletions
diff --git a/README.md b/README.md
index c3fbe46..54d8839 100644
--- a/README.md
+++ b/README.md
@@ -3,3 +3,15 @@ fedidag/client
Fedidag is a wip DAG-based discussion platform and client for the Fediverse.
This repository contains the front-end and a sample data.
+
+# Running locally (development)
+To load Mastodon threads, a CORS proxy is needed. You can run it like this:
+
+ $ yarn cors
+
+Then the dev server can be started:
+
+ $ yarn start
+
+# Running using docker
+The `Dockerfile` sets up NGINX with its own CORS proxy at `/remote/...`.
diff --git a/cors.js b/cors.js
new file mode 100644
index 0000000..a9dc382
--- /dev/null
+++ b/cors.js
@@ -0,0 +1,9 @@
+var host = process.env.HOST || '0.0.0.0';
+var port = process.env.PORT || 8088;
+
+var cors_proxy = require('cors-anywhere');
+cors_proxy.createServer({
+ originWhitelist: [], // Allow all origins
+}).listen(port, host, function() {
+ console.log('Running CORS Anywhere on ' + host + ':' + port);
+});
diff --git a/package.json b/package.json
index 0c0cba0..b026c22 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,8 @@
"name": "fedidag-client",
"version": "0.0.1",
"scripts": {
- "watch": "CORS_ORIGIN=http://localhost:8088 webpack serve -w --host 0.0.0.0",
+ "start": "CORS_PREFIX=http://localhost:8088 webpack serve -w --host 0.0.0.0",
+ "cors": "node cors.js",
"build": "webpack --config ./webpack.config.js --mode production --progress"
},
"babel": {
@@ -28,7 +29,6 @@
"classnames": "^2.2.6",
"color-hash": "^1.0.3",
"core-js": "^3.8.3",
- "cors-anywhere": "^0.4.3",
"date-fns": "^2.16.1",
"jsonld": "^3.3.0",
"preact": "^10.5.12",
@@ -45,6 +45,7 @@
"html-webpack-plugin": "^4.5.0",
"webpack": "^5.17.0",
"webpack-cli": "^4.4.0",
+ "cors-anywhere": "^0.4.3",
"webpack-dev-server": "^3.11.2"
}
}
diff --git a/src/index.js b/src/index.js
index 5fdda36..e94dec9 100644
--- a/src/index.js
+++ b/src/index.js
@@ -14,9 +14,9 @@ const context = [
];
-const corsOrigin = process.env.CORS_ORIGIN || location.origin;
-console.log(corsOrigin);
-const cors = (url) => `${corsOrigin}/remote/${url}`;
+const corsPrefix = process.env.CORS_PREFIX || `${location.origin}/remote`;
+console.log(corsPrefix);
+const cors = (url) => `${corsPrefix}/${url}`;
function wrapCache(target) {
const orig = target.descriptor.value;
diff --git a/webpack.config.js b/webpack.config.js
index 318bc35..ac522d6 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -27,7 +27,7 @@ module.exports = {
new webpack.EnvironmentPlugin({
NODE_ENV: 'production',
DEBUG: false,
- CORS_ORIGIN: null,
+ CORS_PREFIX: null,
}),
new HtmlWebpackPlugin({
title: 'FediDag'