gofasta serve
Starts the HTTP server in production mode. Unlike gofasta dev, this command runs the compiled binary directly without hot reload or file watching. Use this command when deploying your application or when you do not need live reloading.
Usage
gofasta serve [flags]Run this command from the root directory of your Gofasta project after building.
Flags
| Flag | Short | Default | Description |
|---|---|---|---|
--port | -p | 8080 | Port number for the HTTP server |
--host | -H | 0.0.0.0 | Host address to bind to |
--env | -e | production | Environment configuration to load |
Examples
Start the production server with defaults:
gofasta serveStart on a custom port:
gofasta serve --port 3000Start with a specific environment configuration:
gofasta serve --env stagingBind to localhost only:
gofasta serve --host 127.0.0.1 -p 9090Production Deployment
For production, you typically build the binary first and then run it:
go build -o server ./cmd/serve.go
./serverOr use the provided Docker setup:
docker build -t myapp .
docker run -p 8080:8080 myappThe included Dockerfile uses a multi-stage build to produce a minimal production image:
# Build stage
FROM golang:1.23-alpine AS builder
WORKDIR /app
COPY . .
RUN go build -o server ./cmd/serve.go
# Runtime stage
FROM alpine:3.19
COPY --from=builder /app/server /server
COPY --from=builder /app/config /config
EXPOSE 8080
CMD ["/server"]Environment Configuration
The --env flag determines which configuration to load from config/config.yaml. This controls database connections, JWT secrets, SMTP settings, and other environment-specific values.
Available Endpoints
Once the server is running, the following endpoints are available:
| Endpoint | URL |
|---|---|
| REST API | http://localhost:8080/api/v1/ |
| GraphQL | http://localhost:8080/graphql |
| Health Check | http://localhost:8080/health |
| Swagger UI | http://localhost:8080/swagger/index.html |
Related
- gofasta dev — start the development server with hot reload
- gofasta migrate — run migrations before starting the server
- gofasta seed — seed the database before starting