Skip to Content

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

FlagShortDefaultDescription
--port-p8080Port number for the HTTP server
--host-H0.0.0.0Host address to bind to
--env-eproductionEnvironment configuration to load

Examples

Start the production server with defaults:

gofasta serve

Start on a custom port:

gofasta serve --port 3000

Start with a specific environment configuration:

gofasta serve --env staging

Bind to localhost only:

gofasta serve --host 127.0.0.1 -p 9090

Production Deployment

For production, you typically build the binary first and then run it:

go build -o server ./cmd/serve.go ./server

Or use the provided Docker setup:

docker build -t myapp . docker run -p 8080:8080 myapp

The 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:

EndpointURL
REST APIhttp://localhost:8080/api/v1/
GraphQLhttp://localhost:8080/graphql
Health Checkhttp://localhost:8080/health
Swagger UIhttp://localhost:8080/swagger/index.html
Last updated on