Skip to content

Commit e936510

Browse files
authored
Merge pull request #3 from FormeraApp/develop
Enhances settings and backend API configuration
2 parents d1662db + 97fa537 commit e936510

26 files changed

Lines changed: 299 additions & 105 deletions

File tree

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# FRONTEND CONFIGURATION
33
# =============================================================================
44
BASE_URL=http://localhost:3000
5-
API_URL=http://localhost:8080/api
5+
API_URL=http://localhost:8080
66

77
# =============================================================================
88
# BACKEND CONFIGURATION

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ services:
4848
ports:
4949
- "3000:3000"
5050
environment:
51-
- NUXT_PUBLIC_BASE_URL=http://localhost:3000
52-
- NUXT_PUBLIC_API_URL=http://localhost:8080/api
51+
- BASE_URL=http://localhost:3000
52+
- API_URL=http://localhost:8080
5353
depends_on:
5454
- backend
5555

@@ -78,8 +78,8 @@ docker run -d \
7878
```bash
7979
docker run -d \
8080
-p 3000:3000 \
81-
-e NUXT_PUBLIC_BASE_URL=http://localhost:3000 \
82-
-e NUXT_PUBLIC_API_URL=http://localhost:8080/api \
81+
-e BASE_URL=http://localhost:3000 \
82+
-e API_URL=http://localhost:8080 \
8383
ghcr.io/formeraapp/formera-frontend:latest
8484
```
8585

@@ -99,8 +99,8 @@ cd frontend && yarn install && yarn dev
9999

100100
| Variable | Description | Default |
101101
|----------|-------------|---------|
102-
| `NUXT_PUBLIC_BASE_URL` | Public URL of the frontend | `http://localhost:3000` |
103-
| `NUXT_PUBLIC_API_URL` | Backend API URL | `http://localhost:8080/api` |
102+
| `BASE_URL` | Public URL of the frontend | `http://localhost:3000` |
103+
| `API_URL` | Backend base URL | `http://localhost:8080` |
104104

105105
### Backend
106106

@@ -176,8 +176,8 @@ services:
176176
image: ghcr.io/formeraapp/formera-frontend:latest
177177
restart: unless-stopped
178178
environment:
179-
- NUXT_PUBLIC_BASE_URL=https://forms.example.com
180-
- NUXT_PUBLIC_API_URL=https://forms.example.com/api
179+
- BASE_URL=https://forms.example.com
180+
- API_URL=https://forms.example.com
181181
labels:
182182
- "traefik.enable=true"
183183
- "traefik.http.routers.formera.rule=Host(`forms.example.com`)"

backend/cmd/server/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ func initStorage(cfg *config.Config) (storage.Storage, error) {
179179

180180
return s3Store, nil
181181
default:
182-
// Build full URL for local storage (ApiURL + LocalURL path)
183-
apiURL := cfg.ApiURL + cfg.Storage.LocalURL
184-
return storage.NewLocalStorage(cfg.Storage.LocalPath, apiURL)
182+
// ApiURL is the backend base URL (e.g., http://localhost:8080)
183+
uploadsURL := cfg.ApiURL + cfg.Storage.LocalURL
184+
return storage.NewLocalStorage(cfg.Storage.LocalPath, uploadsURL)
185185
}
186186
}
187187

backend/internal/config/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func init() {
3232
type Config struct {
3333
Port string
3434
BaseURL string // Frontend URL (e.g., http://localhost:3000)
35-
ApiURL string // Backend API URL (e.g., http://localhost:8080/api)
35+
ApiURL string // Backend base URL (e.g., http://localhost:8080)
3636
DBPath string
3737
JWTSecret string
3838
CorsOrigin string
@@ -100,7 +100,7 @@ func Load() *Config {
100100

101101
port := getEnv("PORT", "8080")
102102
baseURL := getEnv("BASE_URL", "http://localhost:3000")
103-
apiURL := getEnv("API_URL", "http://localhost:"+port+"/api")
103+
apiURL := getEnv("API_URL", "http://localhost:"+port)
104104

105105
// CORS_ORIGIN defaults to BASE_URL if not set (same-origin deployment)
106106
corsOrigin := getEnv("CORS_ORIGIN", "")

backend/internal/handlers/form.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ func (h *FormHandler) Update(c *gin.Context) {
243243
if req.Slug != nil {
244244
slug := *req.Slug
245245
if slug == "" {
246-
form.Slug = ""
246+
// When slug is cleared, use first 8 chars of ID (form accessible via ID)
247+
form.Slug = form.ID[:8]
247248
} else {
248249
slug = normalizeSlug(slug)
249250
if !isValidSlug(slug) {

backend/internal/handlers/setup.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ type SetupStatusResponse struct {
2727
LogoShowText bool `json:"logo_show_text"`
2828
FaviconURL string `json:"favicon_url"`
2929
LoginBackgroundURL string `json:"login_background_url"`
30+
Language string `json:"language"`
31+
Theme string `json:"theme"`
3032
}
3133

3234
type SetupRequest struct {
@@ -56,6 +58,8 @@ func (h *SetupHandler) GetStatus(c *gin.Context) {
5658
LogoShowText: settings.LogoShowText,
5759
FaviconURL: settings.FaviconURL,
5860
LoginBackgroundURL: settings.LoginBackgroundURL,
61+
Language: settings.Language,
62+
Theme: settings.Theme,
5963
})
6064
}
6165

@@ -130,6 +134,8 @@ type UpdateSettingsRequest struct {
130134
LogoShowText *bool `json:"logo_show_text"`
131135
FaviconURL *string `json:"favicon_url"`
132136
LoginBackgroundURL *string `json:"login_background_url"`
137+
Language string `json:"language"`
138+
Theme string `json:"theme"`
133139
}
134140

135141
func (h *SetupHandler) UpdateSettings(c *gin.Context) {
@@ -166,6 +172,12 @@ func (h *SetupHandler) UpdateSettings(c *gin.Context) {
166172
if req.LoginBackgroundURL != nil {
167173
settings.LoginBackgroundURL = *req.LoginBackgroundURL
168174
}
175+
if req.Language != "" {
176+
settings.Language = req.Language
177+
}
178+
if req.Theme != "" {
179+
settings.Theme = req.Theme
180+
}
169181

170182
database.DB.Save(&settings)
171183

backend/internal/models/form.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ type Form struct {
157157

158158
func (f *Form) BeforeCreate(tx *gorm.DB) error {
159159
f.ID = uuid.New().String()
160+
// Auto-generate unique slug from ID if not set
161+
if f.Slug == "" {
162+
// Use first 8 characters of UUID as slug (unique enough)
163+
f.Slug = f.ID[:8]
164+
}
160165
if f.Status == "" {
161166
f.Status = FormStatusDraft
162167
}

backend/internal/models/settings.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ type Settings struct {
4949
LogoShowText bool `json:"logo_show_text" gorm:"default:true"`
5050
FaviconURL string `json:"favicon_url"`
5151
LoginBackgroundURL string `json:"login_background_url"`
52-
CreatedAt time.Time `json:"created_at"`
53-
UpdatedAt time.Time `json:"updated_at"`
52+
// Language and Theme
53+
Language string `json:"language" gorm:"default:en"`
54+
Theme string `json:"theme" gorm:"default:system"` // "light", "dark", or "system"
55+
CreatedAt time.Time `json:"created_at"`
56+
UpdatedAt time.Time `json:"updated_at"`
5457
}
5558

5659
func GetDefaultSettings() *Settings {
@@ -65,5 +68,7 @@ func GetDefaultSettings() *Settings {
6568
LogoShowText: true,
6669
FaviconURL: "",
6770
LoginBackgroundURL: "",
71+
Language: "en",
72+
Theme: "system",
6873
}
6974
}

frontend/Dockerfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,19 @@ RUN apk add --no-cache ca-certificates tzdata
2020
WORKDIR /app
2121

2222
COPY --from=builder /app/.output ./.output
23+
COPY docker-entrypoint.sh /docker-entrypoint.sh
2324

24-
# Environment variables (override with NUXT_PUBLIC_BASE_URL and NUXT_PUBLIC_API_URL)
25-
ENV NUXT_PUBLIC_BASE_URL=http://localhost:3000
26-
ENV NUXT_PUBLIC_API_URL=http://localhost:8080/api
25+
RUN chmod +x /docker-entrypoint.sh
26+
27+
# Environment variables - use simple BASE_URL and API_URL
28+
ENV BASE_URL=http://localhost:3000
29+
ENV API_URL=http://localhost:8080
2730
ENV NITRO_PORT=3000
2831

2932
EXPOSE 3000
3033

3134
RUN addgroup -S app && adduser -S app -G app \
3235
&& chown -R app:app /app
3336
USER app
37+
ENTRYPOINT ["/docker-entrypoint.sh"]
3438
CMD ["node", ".output/server/index.mjs"]

frontend/app/app.vue

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
<script lang="ts" setup>
2-
onMounted(() => {
3-
const theme = localStorage.getItem("theme");
4-
if (theme) {
5-
document.documentElement.setAttribute("data-theme", theme);
6-
} else if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
7-
document.documentElement.setAttribute("data-theme", "dark");
8-
}
9-
});
10-
</script>
11-
121
<template>
132
<div style="z-index: 9998">
143
<NuxtLayout>

0 commit comments

Comments
 (0)