Skip to content

Commit

Permalink
Merge branch 'compdemocracy:edge' into edge
Browse files Browse the repository at this point in the history
  • Loading branch information
mashbean authored Nov 22, 2023
2 parents a3a9b68 + fc2ab63 commit 1200d3d
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 120 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cypress-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
if: failure()
run: |
echo "Health check failed. Dumping Docker logs..."
docker-compose logs
docker compose -f docker-compose.yml -f docker-compose.test.yml --env-file test.env logs
- name: Cypress Run
uses: cypress-io/github-action@v5
Expand Down
96 changes: 22 additions & 74 deletions client-admin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client-admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"prop-types": "~15.7.2",
"react": "~16.14.0",
"react-dom": "~16.14.0",
"react-easy-emoji": "~1.4.0",
"react-easy-emoji": "~1.8.1",
"react-redux": "7.2.2",
"react-router-dom": "~5.2.0",
"redux": "~4.0.5",
Expand Down
8 changes: 5 additions & 3 deletions client-report/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

const common = require('./webpack.common');
const path = require('path');
const webpack = require("webpack");
const CompressionPlugin = require("compression-webpack-plugin");
const webpack = require('webpack');
const CompressionPlugin = require('compression-webpack-plugin');
const EventHooksPlugin = require('event-hooks-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const writeHeadersJsonTask = require('./writeHeadersJsonTask');
Expand All @@ -14,6 +14,7 @@ module.exports = {
output: {
filename: 'report_bundle.[contenthash].js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/',
clean: true,
},
plugins: [
Expand All @@ -34,7 +35,8 @@ module.exports = {
filename: 'report_style.[contenthash].css',
}),
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify("production")
'process.env.NODE_ENV': JSON.stringify('production'),
'process.env.SERVICE_URL': null,
})
],
performance: {
Expand Down
1 change: 1 addition & 0 deletions client-report/webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
output: {
filename: 'report_bundle.js',
path: path.resolve(__dirname, 'devel'),
publicPath: '/',
},
plugins: [
...common.plugins,
Expand Down
15 changes: 13 additions & 2 deletions example.env
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ SERVER_LOG_LEVEL=
# Optional DB replica for reads:
READ_ONLY_DATABASE_URL=
POSTGRES_DB=polis-dev
POSTGRES_HOST=postgres:5432
POSTGRES_PASSWORD=oiPorg3Nrz0yqDLE
POSTGRES_PORT=5432
POSTGRES_HOST=postgres:${POSTGRES_PORT}
POSTGRES_USER=postgres
POSTGRES_PASSWORD=oiPorg3Nrz0yqDLE
DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}/${POSTGRES_DB}


Expand Down Expand Up @@ -125,3 +125,14 @@ ENCRYPTION_PASSWORD_00001=
# (Deprecated) Basic Auth settings for certain requests between math and api services.
WEBSERVER_PASS=ws-pass
WEBSERVER_USERNAME=ws-user


###### CLIENT SIDE CONFIG ######
# If building client assets, only the following variables are needed:
# * EMBED_SERVICE_HOSTNAME
# * FB_APP_ID
# * GA_TRACKING_ID
# * ENABLE_TWITTER_WIDGETS
# * SERVICE_URL (if static assests are served from a separate domain than API, as described above)


41 changes: 2 additions & 39 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1131,12 +1131,6 @@ function initializePolisHelpers() {
"", // for API
];

let whitelistedBuckets = {
"pol.is": "pol.is",
"embed.pol.is": "pol.is",
"survey.pol.is": "survey.pol.is",
"preprod.pol.is": "preprod.pol.is",
};
function hasWhitelistMatches(host: string) {
let hostWithoutProtocol = host;
if (host.startsWith("http://")) {
Expand Down Expand Up @@ -13330,7 +13324,7 @@ Thanks for using Polis!
}

function proxy(req: { headers?: { host: string }; path: any }, res: any) {
let hostname = buildStaticHostname(req, res);
let hostname = Config.staticFilesHost;
if (!hostname) {
let host = req?.headers?.host || "";
let re = new RegExp(Config.getServerHostname() + "$");
Expand Down Expand Up @@ -13367,37 +13361,6 @@ Thanks for using Polis!
// }
}

function buildStaticHostname(req: { headers?: { host: string } }, res: any) {
if (devMode || domainOverride) {
return Config.staticFilesHost;
} else {
let origin = req?.headers?.host;
// Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ "pol.is": string; "embed.pol.is": string; "survey.pol.is": string; "preprod.pol.is": string; }'.
// No index signature with a parameter of type 'string' was found on type '{ "pol.is": string; "embed.pol.is": string; "survey.pol.is": string; "preprod.pol.is": string; }'.ts(7053)
// @ts-ignore
if (!whitelistedBuckets[origin || ""]) {
if (hasWhitelistMatches(origin || "")) {
// Use the prod bucket for non pol.is domains
return (
whitelistedBuckets["pol.is"] + "." + Config.staticFilesHost
);
} else {
logger.error(
"got request with host that's not whitelisted: (" +
req?.headers?.host +
")"
);
return;
}
}
// Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ "pol.is": string; "embed.pol.is": string; "survey.pol.is": string; "preprod.pol.is": string; }'.
// No index signature with a parameter of type 'string' was found on type '{ "pol.is": string; "embed.pol.is": string; "survey.pol.is": string; "preprod.pol.is": string; }'.ts(7053)
// @ts-ignore
origin = whitelistedBuckets[origin || ""];
return origin + "." + Config.staticFilesHost;
}
}

function makeRedirectorTo(path: string) {
return function (
req: { headers?: { host: string } },
Expand Down Expand Up @@ -13473,7 +13436,7 @@ Thanks for using Polis!
req: { headers?: { host: any }; path: any; pipe: (arg0: any) => void },
res: { set: (arg0: any) => void }
) {
let hostname = buildStaticHostname(req, res);
let hostname = Config.staticFilesHost;
if (!hostname) {
fail(res, 500, "polis_err_file_fetcher_serving_to_domain");
return;
Expand Down

0 comments on commit 1200d3d

Please sign in to comment.