Skip to content

feat: Add embedded frontend support with Go embed#16

Merged
nickmisasi merged 4 commits intomasterfrom
feature/embedded-frontend
Oct 1, 2025
Merged

feat: Add embedded frontend support with Go embed#16
nickmisasi merged 4 commits intomasterfrom
feature/embedded-frontend

Conversation

@fmartingr
Copy link
Copy Markdown
Contributor

@fmartingr fmartingr commented Oct 1, 2025

🎯 Overview

This PR implements a new Make target that creates a single binary containing both the server and React frontend using Go's standard embed library.

✨ Key Features

  • Single Binary Deployment: Creates (~97MB) with embedded React frontend
  • Smart Routing: Automatically serves static files, handles SPA routing, and preserves API functionality
  • Auto-Detection: Server detects embedded assets vs runs in API-only mode
  • Proper MIME Types: All static assets served with correct content types
  • Clean Architecture: Separate package for embedding logic

🚀 Usage

# Build server with embedded frontend
make build-server-embedded

# Run server (serves frontend at localhost:8070)
./build/mcnb-server server

✅ Testing

Comprehensive testing completed:

  • ✅ Static files served with correct MIME types (CSS, JS, images, JSON)
  • ✅ SPA routing works (unknown routes serve index.html)
  • ✅ API routes preserved and functional
  • ✅ Binary size confirms embedded assets (~97MB vs ~small MB without)

🔧 Technical Details

  • Uses Go 1.16+ package for zero-dependency asset embedding
  • Custom SPA handler serves files directly or falls back to index.html
  • API routes at unaffected and work as before
  • Build process copies webapp/build to static/build temporarily during compilation

This enables true single-binary deployment while maintaining all existing functionality.

Implements a new Make target 'build-server-embedded' that creates a single
binary containing both the server and React frontend using Go's standard
embed library.

Key Features:
- New 'static' package with embed.go for asset embedding
- Smart routing: serves static files, handles SPA routing, preserves API
- Automatic detection of embedded assets vs API-only mode
- Single deployable binary (~97MB with embedded frontend)
- Proper MIME type detection for all asset types

Changes:
- Makefile: Added build-webapp and build-server-embedded targets
- cmd/mcnb/server.go: Added embedded file serving with SPA routing support
- static/embed.go: New package using //go:embed directive for asset embedding

Usage:
  make build-server-embedded  # Build server with embedded frontend
  ./build/mcnb-server server  # Run server serving frontend at localhost:8070

The server automatically detects embedded assets and serves the React app
while maintaining full API functionality at /api/v1/* endpoints.
- Update Go version from 1.22.0 to 1.24 to match current toolchain
- Replace deprecated golint with modern staticcheck linter
- Update dependencies with 'go mod tidy'
- Remove unused defaultLocalServerAPI constant
- Add placeholder .gitkeep file to enable embed pattern during development

This resolves linting compatibility issues and ensures our new embedded
frontend code passes all style checks with modern tooling.
Replace hardcoded GO_VERSION environment variable with go-version-file
parameter in actions/setup-go. This ensures CI automatically uses the
exact Go version specified in go.mod without manual updates.

Benefits:
- Eliminates version drift between go.mod and CI
- Automatic updates when go.mod version changes
- Reduces maintenance overhead
- Fix error string capitalization (ST1005)
- Simplify boolean returns (S1008)
- Replace manual loop with append operation (S1011)
- Remove unused struct field (U1000)

Fixed issues in:
- api/response_writer_wrapper.go: Lowercase error message
- model/mattermost.go: Simplify IsValid() methods
- providers/aws.go: Optimize role collection loop, fix error message
- providers/custom.go: Remove unused kubeClient field, fix error messages

All staticcheck and go vet checks now pass successfully.
@nickmisasi nickmisasi merged commit 25cae4f into master Oct 1, 2025
1 check passed
@nickmisasi nickmisasi deleted the feature/embedded-frontend branch October 1, 2025 20:11
nickmisasi added a commit that referenced this pull request Oct 2, 2025
fmartingr added a commit that referenced this pull request Oct 2, 2025
nickmisasi added a commit that referenced this pull request Oct 7, 2025
* Add support for AWS session token

* Change operator spec version

* use latest

* Disable telemetry

* Really disable

* Strip out telemetry

* fix aws kube credential issues

* Add better support for multiple users leveraging the bootstrapper at once

* Proper state persistence

* Use database config in deployemnts

* Adds support for adding MattermostEnv variables via edit installation modal

* Revert "feat: Add embedded frontend support with Go embed (#16)"

This reverts commit 25cae4f.

* Fix 400
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants