Skip to content

Commit

Permalink
Fix env variables for url to taitan
Browse files Browse the repository at this point in the history
  • Loading branch information
foodelevator committed May 24, 2024
1 parent 22066a1 commit 2c44872
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ NOTE: when building with podman, you may need to specify `--ulimit nofile=65535:

| Name | Default | Description |
|--------------------|--------------------------------------|-----------------------------------------------------------------------------------------------------------|
| TAITAN_URL | https://taitan.datasektionen.se | URL to get contents from taitan on |
| RAZZLE_TAITAN_URL | https://taitan.datasektionen.se | URL to get contents from taitan on. **Set during build**. Should probably be the same as TAITAN_URL |
| RAZZLE_CALYPSO_URL | https://calypso.datasektionen.se/api | URL to get news from calypso on. **Set during build** |
| TAITAN_URL | https://taitan.datasektionen.se | URL to taitan from the backend. |
| RAZZLE_TAITAN_URL | https://taitan.datasektionen.se | URL to taitan from the frontend. **Set during both build and run**. |
| RAZZLE_CALYPSO_URL | https://calypso.datasektionen.se/api | URL to get news from calypso on. **Set during both build and run**. |
| TAITAN_CACHE_TTL | 3600 | Time to keep content from taitan cached in seconds. Tip: Set to 0 if using local taitan & bawang-content. |
| CALYPSO_CACHE_TTL | 30 | Time to keep news from calypso cached in seconds. Tip: Set to 0 if using local calypso. |
| PORT | 3000 | Port to listen on |
Expand Down
2 changes: 1 addition & 1 deletion job.nomad.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ job "bawang" {

template {
data = <<ENV
TAITAN_URL=https://taitan.betasektionen.se
TAITAN_URL=http://taitan.nomad.dsekt.internal
PORT={{ env "NOMAD_PORT_http" }}
ENV
destination = "local/.env"
Expand Down
12 changes: 6 additions & 6 deletions src/components/Taitan.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import { HTTPError } from '../HTTPError'
import fetch from 'cross-fetch'

import { DataLoader } from './DataLoader'
import { TAITAN_URL } from '../utility/env'

const RAZZLE_TAITAN_URL = process.env.RAZZLE_TAITAN_URL || 'https://taitan.datasektionen.se'
const TAITAN_CACHE_TTL = process.env.TAITAN_CACHE_TTL ? parseInt(process.env.TAITAN_CACHE_TTL, 10) : 60 * 60

const taitanFetcher = url =>
fetch(url)
.then(res => {
const redirected = res.url !== url // node-fetch doesnt have the res.redirected property
if(redirected) {
if(res.url.startsWith(RAZZLE_TAITAN_URL)) {
return { redirect: res.url.substr(RAZZLE_TAITAN_URL.length) }
if (redirected) {
if (res.url.startsWith(TAITAN_URL)) {
return { redirect: res.url.substring(TAITAN_URL.length) }
} else {
return { redirect: res.url }
}
Expand All @@ -25,11 +25,11 @@ const taitanFetcher = url =>
throw new HTTPError(res.status)
}
})
.then(res => ({ status: 200, redirect: false, ...res }))
.then(res => ({ status: 200, redirect: false, ...res }));

export const Taitan = ({ pathname, children }) =>
<DataLoader
cacheKey={RAZZLE_TAITAN_URL + pathname}
cacheKey={TAITAN_URL + pathname}
fetcher={taitanFetcher}
ttl={TAITAN_CACHE_TTL}
>
Expand Down
5 changes: 2 additions & 3 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import { HeadProvider } from 'react-head'
import { ServerStyleSheet } from 'styled-components'

import { Provider } from './components/DataLoader'

const TAITAN_URL = process.env.TAITAN_URL || 'https://taitan.datasektionen.se'
import { FRONTEND_TAITAN_URL } from './utility/env'

const assets = require(process.env.RAZZLE_ASSETS_MANIFEST)

Expand All @@ -30,7 +29,7 @@ console.log('RAZZLE_ASSETS_MANIFEST', process.env.RAZZLE_ASSETS_MANIFEST)
server
.disable('x-powered-by')
.use(express.static(process.env.RAZZLE_PUBLIC_DIR))
.get('/fuzzyfile', (req, res) => res.redirect(TAITAN_URL + '/fuzzyfile'))
.get('/fuzzyfile', (req, res) => res.redirect(FRONTEND_TAITAN_URL + '/fuzzyfile'))
.get('/*', async (req, res) => {
const context = {}
const promises = []
Expand Down
3 changes: 3 additions & 0 deletions src/utility/env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// In the server, both of these may be set, but in the client, only RAZZLE_* environment variables can be seen.
export const TAITAN_URL = process.env.TAITAN_URL || process.env.RAZZLE_TAITAN_URL || "https://taitan.datasektionen.se";
export const FRONTEND_TAITAN_URL = process.env.RAZZLE_TAITAN_URL || "https://taitan.datasektionen.se"

0 comments on commit 2c44872

Please sign in to comment.