From 5cf183ec6f0ef2046f815635e1d947b8ff894435 Mon Sep 17 00:00:00 2001 From: Vyacheslav Matyukhin Date: Mon, 11 Apr 2022 21:03:47 +0300 Subject: [PATCH 01/13] ops: initial terraform config --- tf/.gitignore | 2 ++ tf/main.tf | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 tf/.gitignore create mode 100644 tf/main.tf diff --git a/tf/.gitignore b/tf/.gitignore new file mode 100644 index 0000000..3fd4f08 --- /dev/null +++ b/tf/.gitignore @@ -0,0 +1,2 @@ +/*.tfstate* +/.terraform* diff --git a/tf/main.tf b/tf/main.tf new file mode 100644 index 0000000..17f4a71 --- /dev/null +++ b/tf/main.tf @@ -0,0 +1,33 @@ +terraform { + required_providers { + vercel = { + source = "vercel/vercel" + version = "~> 0.1" + } + } +} + +provider "vercel" { + # Or omit this for the api_token to be read + # from the VERCEL_API_TOKEN environment variable + # api_token = var.vercel_api_token +} + +resource "vercel_project" "with_git" { + name = "metaforecast-test" + team_id = "quantified-uncertainty" + framework = "nextjs" + + environment = [ + { + key = "NEXT_PUBLIC_ALGOLIA_APP_ID" + value = "96UD3NTQ7L" + target = ["production"] + } + ] + + git_repository = { + type = "github" + repo = "berekuk/metaforecast" + } +} From 5f19ff1c98f0f5443ce7b9b85bef05224e05d59c Mon Sep 17 00:00:00 2001 From: Vyacheslav Matyukhin Date: Mon, 11 Apr 2022 22:38:00 +0300 Subject: [PATCH 02/13] ops: domain, .env generator --- tf/.gitignore | 1 + tf/main.tf | 33 ++++++++++++++++++++++++--------- tf/variables.tf | 7 +++++++ 3 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 tf/variables.tf diff --git a/tf/.gitignore b/tf/.gitignore index 3fd4f08..3e4aae0 100644 --- a/tf/.gitignore +++ b/tf/.gitignore @@ -1,2 +1,3 @@ /*.tfstate* /.terraform* +/prod.tfvars diff --git a/tf/main.tf b/tf/main.tf index 17f4a71..cad41c0 100644 --- a/tf/main.tf +++ b/tf/main.tf @@ -4,30 +4,45 @@ terraform { source = "vercel/vercel" version = "~> 0.1" } + local = { + source = "hashicorp/local" + version = "~> 2" + } } } provider "vercel" { - # Or omit this for the api_token to be read - # from the VERCEL_API_TOKEN environment variable - # api_token = var.vercel_api_token + api_token = var.vercel_api_token } -resource "vercel_project" "with_git" { - name = "metaforecast-test" +resource "vercel_project" "metaforecast" { + name = "metaforecast" team_id = "quantified-uncertainty" framework = "nextjs" environment = [ - { - key = "NEXT_PUBLIC_ALGOLIA_APP_ID" - value = "96UD3NTQ7L" + for k, v in var.metaforecast_env : { + key = k + value = v target = ["production"] } ] git_repository = { type = "github" - repo = "berekuk/metaforecast" + repo = "QURIresearch/metaforecast" } } + +resource "vercel_project_domain" "metaforecast" { + project_id = vercel_project.metaforecast.id + domain = "metaforecast.org" + team_id = "quantified-uncertainty" +} + +// should probably be replaced with local bash script +resource "local_file" "foo" { + content = join("", concat(["# generated by terraform\n"], [for k, v in var.metaforecast_env : "${k} = \"${v}\"\n"])) + filename = "${path.module}/../.env.prod" + file_permission = "0644" +} diff --git a/tf/variables.tf b/tf/variables.tf new file mode 100644 index 0000000..bf3b7fd --- /dev/null +++ b/tf/variables.tf @@ -0,0 +1,7 @@ +variable "metaforecast_env" { + type = map(string) +} + +variable "vercel_api_token" { + type = string +} From bf08d048623878c07e281faecec57eb7782d5486 Mon Sep 17 00:00:00 2001 From: Vyacheslav Matyukhin Date: Mon, 11 Apr 2022 23:44:23 +0300 Subject: [PATCH 03/13] ops: DO, new vercel provider --- tf/main.tf | 72 +++++++++++++++++++++++++++++++++---------------- tf/variables.tf | 17 +++++++++--- 2 files changed, 62 insertions(+), 27 deletions(-) diff --git a/tf/main.tf b/tf/main.tf index cad41c0..4b99bf0 100644 --- a/tf/main.tf +++ b/tf/main.tf @@ -1,8 +1,13 @@ terraform { required_providers { + # official vercel/vercel provider seems less stable vercel = { - source = "vercel/vercel" - version = "~> 0.1" + source = "registry.terraform.io/chronark/vercel" + version = ">=0.10.3" + } + digitalocean = { + source = "digitalocean/digitalocean" + version = "~> 2.0" } local = { source = "hashicorp/local" @@ -12,37 +17,58 @@ terraform { } provider "vercel" { - api_token = var.vercel_api_token + token = var.vercel_api_token +} + +provider "digitalocean" { + token = var.digital_ocean_token +} + +resource "digitalocean_database_cluster" "metaforecast_db" { + name = "postgres-green" + engine = "pg" + size = "db-s-1vcpu-1gb" + region = "nyc1" + node_count = 1 + version = 14 } resource "vercel_project" "metaforecast" { - name = "metaforecast" - team_id = "quantified-uncertainty" - framework = "nextjs" + name = "metaforecast" + team_id = var.vercel_team - environment = [ - for k, v in var.metaforecast_env : { - key = k - value = v - target = ["production"] - } - ] - - git_repository = { + git_repository { type = "github" repo = "QURIresearch/metaforecast" } + + domain { + name = "metaforecast.org" + } } -resource "vercel_project_domain" "metaforecast" { +resource "vercel_env" "metaforecast" { project_id = vercel_project.metaforecast.id - domain = "metaforecast.org" - team_id = "quantified-uncertainty" + team_id = var.vercel_team + type = "plain" + for_each = var.metaforecast_env + key = each.key + value = each.value + target = ["preview", "production"] } -// should probably be replaced with local bash script -resource "local_file" "foo" { - content = join("", concat(["# generated by terraform\n"], [for k, v in var.metaforecast_env : "${k} = \"${v}\"\n"])) - filename = "${path.module}/../.env.prod" - file_permission = "0644" +resource "vercel_env" "metaforecast_db" { + project_id = vercel_project.metaforecast.id + team_id = var.vercel_team + type = "plain" + key = "DIGITALOCEAN_POSTGRES" + value = digitalocean_database_cluster.metaforecast_db.uri + target = ["preview", "production"] } + +# should probably be replaced with local bash script +# resource "local_file" "foo" { +# content = join("", concat(["# generated by terraform\n"], [for k, v in var.metaforecast_env : "${k} = \"${v}\"\n"])) +# filename = "${path.module}/../.env.prod" +# file_permission = "0644" +# } diff --git a/tf/variables.tf b/tf/variables.tf index bf3b7fd..d42020d 100644 --- a/tf/variables.tf +++ b/tf/variables.tf @@ -1,7 +1,16 @@ -variable "metaforecast_env" { - type = map(string) -} - variable "vercel_api_token" { type = string } + +variable "digital_ocean_token" { + type = string +} + +variable "vercel_team" { + type = string + default = "quantified-uncertainty" +} + +variable "metaforecast_env" { + type = map(string) +} From ee07435c623fe6d62dd9165fd44773331c80d759 Mon Sep 17 00:00:00 2001 From: Vyacheslav Matyukhin Date: Tue, 12 Apr 2022 00:10:07 +0300 Subject: [PATCH 04/13] feat: get rid of NEXT_PUBLIC_SITE_URL --- README.md | 2 +- docs/configuration.md | 4 ---- env.example | 2 -- src/pages/dashboards/index.tsx | 2 ++ src/pages/dashboards/view/[id].tsx | 2 ++ src/web/utils.ts | 10 ++++++++++ src/web/worker/getDashboardForecasts.ts | 10 +++++++++- 7 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 src/web/utils.ts diff --git a/README.md b/README.md index 9e1180c..1021081 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ $ npm install You'll need a PostgreSQL instance, either local (see https://www.postgresql.org/download/) or in the cloud (for example, you can spin one up on https://www.digitalocean.com/products/managed-databases-postgresql or https://supabase.com/). -Environment can be set up with an `.env` file. You'll need to configure at least `DIGITALOCEAN_POSTGRES` for the fetching to work, and `NEXT_PUBLIC_SITE_URL` for the frontend. +Environment can be set up with an `.env` file. You'll need to configure at least `DIGITALOCEAN_POSTGRES`. See [./docs/configuration.md](./docs/configuration.md) for details. diff --git a/docs/configuration.md b/docs/configuration.md index fc8fb7b..6254d2e 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -5,14 +5,12 @@ All configuration is done through environment variables. Not all of these are necessary to run the code. The most important ones are: - `DIGITALOCEAN_POSTGRES` pointing to the working Postgres database -- `NEXT_PUBLIC_SITE_URL` for the frontend to work properly There's also a template configuration file in `../env.example`. ## Database endpoints - `DIGITALOCEAN_POSTGRES`, of the form `postgres://username:password@domain.com:port/configvars`. (Disregard `DIGITALOCEAN_` prefix, you can use any endpoint you like). -- `DIGITALOCEAN_POSTGRES_PUBLIC` - `ALGOLIA_MASTER_API_KEY`, a string of 32 hexidecimal characters, like `19b6c2234e50c98d30668659a39e3127` (not an actual key). - `NEXT_PUBLIC_ALGOLIA_APP_ID`, - `NEXT_PUBLIC_ALGOLIA_SEARCH_KEY` @@ -37,7 +35,5 @@ Note that not all of these cookies are needed to use all parts of the source cod ## Others -- `NEXT_PUBLIC_SITE_URL`, e.g., `http://localhost:3000` if you're running a local instance -- `REBUIDNETLIFYHOOKURL` - `BACKUP_PROXY_IP` - `BACKUP_PROXY_PORT` diff --git a/env.example b/env.example index 8145c9d..481bf11 100644 --- a/env.example +++ b/env.example @@ -8,8 +8,6 @@ # DIGITALOCEAN_POSTGRES=postgresql://...@localhost:5432/...?schema=public # POSTGRES_NO_SSL=1 -# NEXT_PUBLIC_SITE_URL=http://localhost:3000 - # DEBUG_MODE=off # INFER_COOKIE=... diff --git a/src/pages/dashboards/index.tsx b/src/pages/dashboards/index.tsx index b0a2743..1e757e6 100644 --- a/src/pages/dashboards/index.tsx +++ b/src/pages/dashboards/index.tsx @@ -8,6 +8,7 @@ import { DashboardCreator } from "../../web/display/DashboardCreator"; import { Layout } from "../../web/display/Layout"; import { LineHeader } from "../../web/display/LineHeader"; import { addLabelsToForecasts, FrontendForecast } from "../../web/platforms"; +import { reqToBasePath } from "../../web/utils"; import { getDashboardForecastsByDashboardId } from "../../web/worker/getDashboardForecasts"; interface Props { @@ -40,6 +41,7 @@ export const getServerSideProps: GetServerSideProps = async ( const { dashboardForecasts, dashboardItem } = await getDashboardForecastsByDashboardId({ dashboardId, + basePath: reqToBasePath(context.req), // required on server side to find the API endpoint }); const frontendDashboardForecasts = addLabelsToForecasts( dashboardForecasts, diff --git a/src/pages/dashboards/view/[id].tsx b/src/pages/dashboards/view/[id].tsx index 128f9f5..7e689c1 100644 --- a/src/pages/dashboards/view/[id].tsx +++ b/src/pages/dashboards/view/[id].tsx @@ -9,6 +9,7 @@ import { InfoBox } from "../../../web/display/InfoBox"; import { Layout } from "../../../web/display/Layout"; import { LineHeader } from "../../../web/display/LineHeader"; import { addLabelsToForecasts, FrontendForecast } from "../../../web/platforms"; +import { reqToBasePath } from "../../../web/utils"; import { getDashboardForecastsByDashboardId } from "../../../web/worker/getDashboardForecasts"; interface Props { @@ -27,6 +28,7 @@ export const getServerSideProps: GetServerSideProps = async ( const { dashboardForecasts, dashboardItem } = await getDashboardForecastsByDashboardId({ dashboardId, + basePath: reqToBasePath(context.req), // required on server side to find the API endpoint }); const frontendDashboardForecasts = addLabelsToForecasts( dashboardForecasts, diff --git a/src/web/utils.ts b/src/web/utils.ts new file mode 100644 index 0000000..c829859 --- /dev/null +++ b/src/web/utils.ts @@ -0,0 +1,10 @@ +import { IncomingMessage } from "http"; + +export const reqToBasePath = (req: IncomingMessage) => { + if (process.env.NEXT_PUBLIC_VERCEL_URL) { + return `https://${process.env.NEXT_PUBLIC_VERCEL_URL}`; + } + + // we could just hardcode http://localhost:3000 here, but then `next dev -p ` would break + return "http://" + req.headers.host; +}; diff --git a/src/web/worker/getDashboardForecasts.ts b/src/web/worker/getDashboardForecasts.ts index 9fb2b25..66e1b77 100644 --- a/src/web/worker/getDashboardForecasts.ts +++ b/src/web/worker/getDashboardForecasts.ts @@ -5,16 +5,24 @@ import { Forecast } from "../../backend/platforms"; export async function getDashboardForecastsByDashboardId({ dashboardId, + basePath, +}: { + dashboardId: string; + basePath?: string; }): Promise<{ dashboardForecasts: Forecast[]; dashboardItem: DashboardItem; }> { console.log("getDashboardForecastsByDashboardId: "); + if (window === undefined && !basePath) { + throw new Error("`basePath` option is required on server side"); + } + let dashboardContents: Forecast[] = []; let dashboardItem: DashboardItem | any = null; try { let { data } = await axios({ - url: `${process.env.NEXT_PUBLIC_SITE_URL}/api/dashboard-by-id`, + url: `${basePath || ""}/api/dashboard-by-id`, method: "post", data: { id: dashboardId, From 860fc1eb7037e692ebcba8723587c1230c7cb3fa Mon Sep 17 00:00:00 2001 From: Vyacheslav Matyukhin Date: Tue, 12 Apr 2022 00:32:34 +0300 Subject: [PATCH 05/13] ops: heroku --- tf/main.tf | 33 +++++++++++++++++++++++---------- tf/variables.tf | 4 ++++ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/tf/main.tf b/tf/main.tf index 4b99bf0..69029a7 100644 --- a/tf/main.tf +++ b/tf/main.tf @@ -9,6 +9,10 @@ terraform { source = "digitalocean/digitalocean" version = "~> 2.0" } + heroku = { + source = "heroku/heroku" + version = "~> 5.0.2" + } local = { source = "hashicorp/local" version = "~> 2" @@ -24,6 +28,11 @@ provider "digitalocean" { token = var.digital_ocean_token } +provider "heroku" { + email = "me@berekuk.ru" + api_key = var.heroku_api_key +} + resource "digitalocean_database_cluster" "metaforecast_db" { name = "postgres-green" engine = "pg" @@ -33,6 +42,19 @@ resource "digitalocean_database_cluster" "metaforecast_db" { version = 14 } +locals { + generated_env = merge(var.metaforecast_env, { + DIGITALOCEAN_POSTGRES = digitalocean_database_cluster.metaforecast_db.uri + }) +} + +resource "heroku_app" "metaforecast_backend" { + name = "metaforecast-backend" + region = "us" + + config_vars = local.generated_env +} + resource "vercel_project" "metaforecast" { name = "metaforecast" team_id = var.vercel_team @@ -51,21 +73,12 @@ resource "vercel_env" "metaforecast" { project_id = vercel_project.metaforecast.id team_id = var.vercel_team type = "plain" - for_each = var.metaforecast_env + for_each = local.generated_env key = each.key value = each.value target = ["preview", "production"] } -resource "vercel_env" "metaforecast_db" { - project_id = vercel_project.metaforecast.id - team_id = var.vercel_team - type = "plain" - key = "DIGITALOCEAN_POSTGRES" - value = digitalocean_database_cluster.metaforecast_db.uri - target = ["preview", "production"] -} - # should probably be replaced with local bash script # resource "local_file" "foo" { # content = join("", concat(["# generated by terraform\n"], [for k, v in var.metaforecast_env : "${k} = \"${v}\"\n"])) diff --git a/tf/variables.tf b/tf/variables.tf index d42020d..fc652ce 100644 --- a/tf/variables.tf +++ b/tf/variables.tf @@ -6,6 +6,10 @@ variable "digital_ocean_token" { type = string } +variable "heroku_api_key" { + type = string +} + variable "vercel_team" { type = string default = "quantified-uncertainty" From 5ab67ce7fe78b24a747757d6fbd3fa65f04ea3ab Mon Sep 17 00:00:00 2001 From: Vyacheslav Matyukhin Date: Tue, 12 Apr 2022 11:01:55 +0300 Subject: [PATCH 06/13] ops: more terraform, docs --- docs/configuration.md | 2 +- docs/infra.md | 45 +++++++++++++++++++++++++++++++++++++++++++ tf/.gitignore | 2 +- tf/main.tf | 2 +- 4 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 docs/infra.md diff --git a/docs/configuration.md b/docs/configuration.md index 6254d2e..881dc3c 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -1,5 +1,6 @@ # Configuration +Code reads its configuration from the environment variables. All configuration is done through environment variables. Not all of these are necessary to run the code. The most important ones are: @@ -23,7 +24,6 @@ Note that not all of these cookies are needed to use all parts of the source cod - `GOODJUDGMENTOPENCOOKIE` - `INFER_COOKIE` -- `CSETFORETELL_COOKIE`, deprecated, superseded by `INFER_COOKIE`. - `HYPERMINDCOOKIE` - `GOOGLE_API_KEY`, necessary to fetch Peter Wildeford's predictions. - `SECRET_BETFAIR_ENDPOINT` diff --git a/docs/infra.md b/docs/infra.md new file mode 100644 index 0000000..5685f5c --- /dev/null +++ b/docs/infra.md @@ -0,0 +1,45 @@ +# Terraform + +Infra is managed by [Terraform](https://www.terraform.io/) (WIP, not everything is migrated yet). + +Managed with Terraform: + +- Vercel +- Digital Ocean (database) +- Heroku + +TODO: + +- Algolia +- Twitter bot +- DNS? + +## Recipes + +### Set up a new dev repo for managing prod + +1. Install [Terraform CLI](https://www.terraform.io/downloads) +2. `cd tf` +3. `terraform init` +4. Get a current version of prod tfvars configuration + - Source is in `metaforecast-notes-and-secrets` secret repo, `tf/prod.auto.tfvars` for now (will move to Terraform Cloud later) + - Store it in `tf/prod.auto.tfvars` (or somewhere else, there are [other ways](https://www.terraform.io/language/values/variables#assigning-values-to-root-module-variables)) +5. Get a current version of terraform state + - Source is in `metaforecast-notes-and-secrets` secret repo for now (will move to Terraform Cloud or [pg backend](https://www.terraform.io/language/settings/backends/pg) later) + - Store it in `tf/terraform.tfstate` + +Now everything is set up. + +Check with `terraform plan`; it should output `"No changes. Your infrastructure matches the configuration."`. + +### Edit environment variables in prod + +1. Update terraform state and vars from `metaforecast-notes-and-secrets` +2. Modify `tf/prod.auto.tfvars` as needed +3. Run `terraform apply` + - Check if proposed actions list is appropriate + - Enter `yes` + - Terraform will push the new configuration to Heroku and Vercel. +4. Push terraform state and vars back to `metaforecast-notes-and-secrets` + +(After we move to Terraform Cloud (1) and (4) won't be needed.) diff --git a/tf/.gitignore b/tf/.gitignore index 3e4aae0..458cf26 100644 --- a/tf/.gitignore +++ b/tf/.gitignore @@ -1,3 +1,3 @@ /*.tfstate* /.terraform* -/prod.tfvars +/prod.*tfvars diff --git a/tf/main.tf b/tf/main.tf index 69029a7..fc2e744 100644 --- a/tf/main.tf +++ b/tf/main.tf @@ -61,7 +61,7 @@ resource "vercel_project" "metaforecast" { git_repository { type = "github" - repo = "QURIresearch/metaforecast" + repo = "quantified-uncertainty/metaforecast" } domain { From 328fdd69bd74c76e8bfc36781ab30cf6c8a87618 Mon Sep 17 00:00:00 2001 From: Vyacheslav Matyukhin Date: Tue, 12 Apr 2022 11:05:30 +0300 Subject: [PATCH 07/13] docs: infra notes in configuration.md --- docs/configuration.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/configuration.md b/docs/configuration.md index 881dc3c..4be5f52 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -1,12 +1,15 @@ # Configuration -Code reads its configuration from the environment variables. All configuration is done through environment variables. Not all of these are necessary to run the code. The most important ones are: - `DIGITALOCEAN_POSTGRES` pointing to the working Postgres database +Environment for production deployments is configured through Terraform, see [infra.md](./infra.md) for details. + +For local development you can write `.env` file by hand or import it from Heroku with `heroku config -s -a metaforecast-backend` and then modify accordingly. + There's also a template configuration file in `../env.example`. ## Database endpoints From 473a372515bd3175e49672583c1af6c86f49c928 Mon Sep 17 00:00:00 2001 From: Vyacheslav Matyukhin Date: Tue, 12 Apr 2022 11:15:33 +0300 Subject: [PATCH 08/13] ops: move heroku_email to vars, set vercel framework --- tf/main.tf | 7 ++++--- tf/variables.tf | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/tf/main.tf b/tf/main.tf index fc2e744..d54a746 100644 --- a/tf/main.tf +++ b/tf/main.tf @@ -29,7 +29,7 @@ provider "digitalocean" { } provider "heroku" { - email = "me@berekuk.ru" + email = var.heroku_email api_key = var.heroku_api_key } @@ -56,8 +56,9 @@ resource "heroku_app" "metaforecast_backend" { } resource "vercel_project" "metaforecast" { - name = "metaforecast" - team_id = var.vercel_team + name = "metaforecast" + team_id = var.vercel_team + framework = "nextjs" git_repository { type = "github" diff --git a/tf/variables.tf b/tf/variables.tf index fc652ce..450d3fb 100644 --- a/tf/variables.tf +++ b/tf/variables.tf @@ -10,6 +10,10 @@ variable "heroku_api_key" { type = string } +variable "heroku_email" { + type = string +} + variable "vercel_team" { type = string default = "quantified-uncertainty" From 846e235e0c28b0cbffeaa37d9beb3ac998f57e5e Mon Sep 17 00:00:00 2001 From: Vyacheslav Matyukhin Date: Tue, 12 Apr 2022 11:37:17 +0300 Subject: [PATCH 09/13] fix: NEXT_PUBLIC_VERCEL_URL usage --- src/web/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/web/utils.ts b/src/web/utils.ts index c829859..2dcd71e 100644 --- a/src/web/utils.ts +++ b/src/web/utils.ts @@ -2,7 +2,7 @@ import { IncomingMessage } from "http"; export const reqToBasePath = (req: IncomingMessage) => { if (process.env.NEXT_PUBLIC_VERCEL_URL) { - return `https://${process.env.NEXT_PUBLIC_VERCEL_URL}`; + return process.env.NEXT_PUBLIC_VERCEL_URL; } // we could just hardcode http://localhost:3000 here, but then `next dev -p ` would break From 651471a961bedb55981543b19349719fff5a6785 Mon Sep 17 00:00:00 2001 From: Vyacheslav Matyukhin Date: Tue, 12 Apr 2022 11:57:14 +0300 Subject: [PATCH 10/13] ops: remove sslmode=require from pg uri --- tf/main.tf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tf/main.tf b/tf/main.tf index d54a746..18dd6c0 100644 --- a/tf/main.tf +++ b/tf/main.tf @@ -44,7 +44,8 @@ resource "digitalocean_database_cluster" "metaforecast_db" { locals { generated_env = merge(var.metaforecast_env, { - DIGITALOCEAN_POSTGRES = digitalocean_database_cluster.metaforecast_db.uri + # should we bring proper DO certificates to prod instead? + DIGITALOCEAN_POSTGRES = replace(digitalocean_database_cluster.metaforecast_db.uri, "/\\?sslmode=require$/", "") }) } From 25fad77f251eefa883ad7c7041a40ec0360afbfe Mon Sep 17 00:00:00 2001 From: Vyacheslav Matyukhin Date: Tue, 12 Apr 2022 11:57:35 +0300 Subject: [PATCH 11/13] fix: basePath check --- src/web/utils.ts | 1 + src/web/worker/getDashboardForecasts.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/web/utils.ts b/src/web/utils.ts index 2dcd71e..65aa456 100644 --- a/src/web/utils.ts +++ b/src/web/utils.ts @@ -2,6 +2,7 @@ import { IncomingMessage } from "http"; export const reqToBasePath = (req: IncomingMessage) => { if (process.env.NEXT_PUBLIC_VERCEL_URL) { + console.log(process.env.NEXT_PUBLIC_VERCEL_URL); return process.env.NEXT_PUBLIC_VERCEL_URL; } diff --git a/src/web/worker/getDashboardForecasts.ts b/src/web/worker/getDashboardForecasts.ts index 66e1b77..ef729c1 100644 --- a/src/web/worker/getDashboardForecasts.ts +++ b/src/web/worker/getDashboardForecasts.ts @@ -14,7 +14,7 @@ export async function getDashboardForecastsByDashboardId({ dashboardItem: DashboardItem; }> { console.log("getDashboardForecastsByDashboardId: "); - if (window === undefined && !basePath) { + if (typeof window === undefined && !basePath) { throw new Error("`basePath` option is required on server side"); } From ba6b11ce6dbbbc3c0458365794b2a24a705312b0 Mon Sep 17 00:00:00 2001 From: Vyacheslav Matyukhin Date: Tue, 12 Apr 2022 12:05:16 +0300 Subject: [PATCH 12/13] fix: reqToBasePath --- src/web/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/web/utils.ts b/src/web/utils.ts index 65aa456..ddee0c1 100644 --- a/src/web/utils.ts +++ b/src/web/utils.ts @@ -3,7 +3,7 @@ import { IncomingMessage } from "http"; export const reqToBasePath = (req: IncomingMessage) => { if (process.env.NEXT_PUBLIC_VERCEL_URL) { console.log(process.env.NEXT_PUBLIC_VERCEL_URL); - return process.env.NEXT_PUBLIC_VERCEL_URL; + return `https://${process.env.NEXT_PUBLIC_VERCEL_URL}`; } // we could just hardcode http://localhost:3000 here, but then `next dev -p ` would break From e4119d61122905a3064b517bcee71d7aba3b1609 Mon Sep 17 00:00:00 2001 From: Vyacheslav Matyukhin Date: Tue, 12 Apr 2022 12:57:36 +0300 Subject: [PATCH 13/13] ops: www domain --- tf/main.tf | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tf/main.tf b/tf/main.tf index 18dd6c0..f76dbf3 100644 --- a/tf/main.tf +++ b/tf/main.tf @@ -69,6 +69,12 @@ resource "vercel_project" "metaforecast" { domain { name = "metaforecast.org" } + + domain { + name = "www.metaforecast.org" + redirect = "metaforecast.org" + redirect_status_code = 308 + } } resource "vercel_env" "metaforecast" {