Skip to content

Commit

Permalink
Use dotenv properly, get api token for jami
Browse files Browse the repository at this point in the history
  • Loading branch information
Keskimaki committed Jan 27, 2023
1 parent 1f0e4b2 commit c76630b
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .env.template
Original file line number Diff line number Diff line change
@@ -1 +1 @@
API_TOKEN=<API_TOKEN>
API_TOKEN=<API_TOKEN>
5 changes: 4 additions & 1 deletion .github/workflows/staging.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Deploy to staging

on: push
on:
push:
branches:
- master

jobs:
test:
Expand Down
22 changes: 0 additions & 22 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,7 @@
export const PORT = process.env.PORT || 8000

export const DB_CONFIG = {
dialect: 'postgres',
pool: {
max: 10,
min: 0,
acquire: 10000,
idle: 300000000,
},
username: process.env.POSTGRES_USER,
password: process.env.POSTGRES_PASSWORD,
port: 5432,
host: process.env.POSTGRES_HOST,
database: process.env.POSTGRES_DATABASE,
logging: false,
}

export const inStaging = process.env.REACT_APP_STAGING === 'true'

export const inProduction = !inStaging && process.env.NODE_ENV === 'production'

export const inE2EMode = process.env.REACT_APP_E2E === 'true'

export const GIT_SHA = process.env.REACT_APP_GIT_SHA || ''

export const JAMI_URL = inProduction
? 'https://importer.cs.helsinki.fi/api/auth'
: 'https://toska-staging.cs.helsinki.fi/jami'
2 changes: 1 addition & 1 deletion src/server/db/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Sequelize, Options } from 'sequelize'
import { Umzug, SequelizeStorage } from 'umzug'

import logger from '../util/logger'
import { DB_CONFIG } from '../../config'
import { DB_CONFIG } from '../util/config'

const DB_CONNECTION_RETRY_LIMIT = 10

Expand Down
2 changes: 1 addition & 1 deletion src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'path'
import { Handlers as SentryHandlers } from '@sentry/node'
import initializeSentry from './util/sentry'

import { PORT } from '../config'
import { PORT } from './util/config'
import { connectToDatabase } from './db/connection'
import logger from './util/logger'
import errorHandler from './middeware/errorHandler'
Expand Down
29 changes: 29 additions & 0 deletions src/server/util/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as dotenv from 'dotenv'

import { inProduction } from '../../config'

dotenv.config()

export const PORT = process.env.PORT || 8000

export const { API_TOKEN } = process.env

export const DB_CONFIG = {
dialect: 'postgres',
pool: {
max: 10,
min: 0,
acquire: 10000,
idle: 300000000,
},
username: process.env.POSTGRES_USER,
password: process.env.POSTGRES_PASSWORD,
port: 5432,
host: process.env.POSTGRES_HOST,
database: process.env.POSTGRES_DATABASE,
logging: false,
}

export const JAMI_URL = inProduction
? 'https://importer.cs.helsinki.fi/api/auth'
: 'https://toska-staging.cs.helsinki.fi/jami'
5 changes: 1 addition & 4 deletions src/server/util/jami.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import axios from 'axios'
import { JAMI_URL, inProduction } from '../../config'
import { JAMI_URL, API_TOKEN } from './config'
import { OrganisationData } from '../types'

const API_TOKEN = process.env

export const jamiClient = axios.create({
baseURL: JAMI_URL,
params: {
token: API_TOKEN,
noLogging: !inProduction,
},
})

Expand Down

0 comments on commit c76630b

Please sign in to comment.