diff options
| author | s-ol <s+removethis@s-ol.nu> | 2022-01-12 09:19:47 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2022-01-12 09:33:13 +0000 |
| commit | 7bcd1e44d3f78a4120be295f6a31b57917cee563 (patch) | |
| tree | 97876551f64f7eb0fb78b963d985bc1d1580d7dc | |
| parent | handle errors while loading more gracefully (diff) | |
| download | fedidag-7bcd1e44d3f78a4120be295f6a31b57917cee563.tar.gz fedidag-7bcd1e44d3f78a4120be295f6a31b57917cee563.zip | |
add instructions and commands for local CORS proxy
| -rw-r--r-- | README.md | 12 | ||||
| -rw-r--r-- | cors.js | 9 | ||||
| -rw-r--r-- | package.json | 5 | ||||
| -rw-r--r-- | src/index.js | 6 | ||||
| -rw-r--r-- | webpack.config.js | 2 |
5 files changed, 28 insertions, 6 deletions
@@ -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/...`. @@ -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' |
