Skip to content

Commit

Permalink
refactor env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
plutov committed Aug 8, 2024
1 parent f4958d3 commit f01d892
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 59 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,12 @@ Go backend:
- `DATABASE_URL` - Postgres connection string
- `LOG_LEVEL` - Log level, e.g. `info`
- `UI_ADDR` - Public address of the UI, e.g. `https://formulosity.vercel.app`
- `SURVEYS_DIR` - Directory with surveys, e.g. `/root/surveys`
UI (.env files):
UI:
- `PUBLIC_APP_URL` - Public address of the UI, e.g. `https://formulosity.vercel.app`
- `CONSOLE_API_ADDR` - Internal address of the Go backend, e.g. `http://api:8080` (could be the same as `NEXT_PUBLIC_CONSOLE_API_ADDR`)
- `NEXT_PUBLIC_CONSOLE_API_ADDR` - Public address of the Go backend
- `NEXT_PUBLIC_CONSOLE_API_ADDR` - Public address of the Go backend. Needs to be set as a build arg for the Docker image, since it's needed for `npm run build`.
- `IRON_SESSION_SECRET` - Secret for session encryption
- `HTTP_BASIC_AUTH` - Format: `user:pass` for basic auth (optional)
Expand Down
7 changes: 6 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ services:
- postgres
environment:
- LOG_LEVEL=debug
- UI_ADDR=http://localhost:3000
- DATABASE_URL=postgres://postgres:postgres@postgres:5432/formulosity?sslmode=disable
- SURVEYS_DIR=/root/surveys
volumes:
Expand All @@ -35,8 +34,14 @@ services:
restart: always
build:
context: ./ui
args:
- NEXT_PUBLIC_CONSOLE_API_ADDR=http://localhost:9900
ports:
- "3000:3000"
environment:
- CONSOLE_API_ADDR=http://api:8080
- IRON_SESSION_SECRET=e75af92dffba8065f2730472f45f2046941fe35f361739d31992f42d88d6bf6c
- HTTP_BASIC_AUTH=user:pass
depends_on:
- postgres
- api
Expand Down
1 change: 1 addition & 0 deletions pkg/controllers/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func NewRouter(h *Handler) *echo.Echo {
e := echo.New()
e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.Use(middleware.CORS())

e.GET("/", h.healthCheckHandler)
e.GET("/app/surveys", h.getSurveys)
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/surveys.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (h *Handler) getSurveys(c echo.Context) error {
}

for i, s := range surveys {
surveys[i].URL = fmt.Sprintf("%s/survey/%s", os.Getenv("UI_ADDR"), s.URLSlug)
surveys[i].URL = fmt.Sprintf("/survey/%s", s.URLSlug)
}

return response.Ok(c, surveys)
Expand Down
5 changes: 0 additions & 5 deletions ui/.env

This file was deleted.

5 changes: 0 additions & 5 deletions ui/.env.production

This file was deleted.

2 changes: 2 additions & 0 deletions ui/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ COPY --from=deps /app/node_modules ./node_modules
COPY . .

ENV NODE_ENV=production
ARG NEXT_PUBLIC_CONSOLE_API_ADDR
ENV NEXT_PUBLIC_CONSOLE_API_ADDR=$NEXT_PUBLIC_CONSOLE_API_ADDR

RUN npm run build

Expand Down
1 change: 0 additions & 1 deletion ui/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export const metadata: Metadata = {
},
description: siteConfig.description,
keywords: [],
metadataBase: new URL(String(siteConfig.url)),
alternates: {
canonical: '/',
},
Expand Down
3 changes: 1 addition & 2 deletions ui/src/app/robots.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { MetadataRoute } from 'next'
import { siteConfig } from 'lib/siteConfig'

export default function robots(): MetadataRoute.Robots {
return {
Expand All @@ -8,6 +7,6 @@ export default function robots(): MetadataRoute.Robots {
allow: '/',
disallow: '/app/',
},
sitemap: `${siteConfig.url}/sitemap.xml`,
sitemap: `/sitemap.xml`,
}
}
40 changes: 1 addition & 39 deletions ui/src/app/sitemap.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,5 @@
import { MetadataRoute } from 'next'
import { siteConfig } from 'lib/siteConfig'

export default function sitemap(): MetadataRoute.Sitemap {
return [
{
url: String(siteConfig.url),
lastModified: new Date(),
changeFrequency: 'yearly',
priority: 1,
},
{
url: `${siteConfig.url}/docs`,
lastModified: new Date(),
changeFrequency: 'monthly',
priority: 0.9,
},
{
url: `${siteConfig.url}/pricing`,
lastModified: new Date(),
changeFrequency: 'weekly',
priority: 0.8,
},
{
url: `${siteConfig.url}/changelog`,
lastModified: new Date(),
changeFrequency: 'weekly',
priority: 0.7,
},
{
url: `${siteConfig.url}/pricing`,
lastModified: new Date(),
changeFrequency: 'yearly',
priority: 0.6,
},
{
url: `${siteConfig.url}/terms`,
lastModified: new Date(),
changeFrequency: 'yearly',
priority: 0.6,
},
]
return []
}
1 change: 0 additions & 1 deletion ui/src/lib/siteConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ export const siteConfig = {
name: 'Formulosity',
description:
'Formulosity is a Surveys as Code platform that empowers users to craft and deploy sophisticated surveys with the ease and flexibility of writing code.',
url: process.env.PUBLIC_APP_URL,
}

0 comments on commit f01d892

Please sign in to comment.