Documentation
Web Frameworks
Standalone

Standalone

Pioneer also come with first-party integration for a standalone server. This aims to make developing with Pioneer even faster by not having to worry about setting up the server.

Under the hood, the standalone server uses the Vapor integration.

import Pioneer
 
let server = Pioneer(
    schema: schema,
    resolver: Resolver(),
    websocketProtocol: .graphqlWs,
    introspection: true,
    playground: .sandbox
)
 
try server.standaloneServer()

Configuration

The standalone server allow some configuration to be better suited for your use case and environment.

Port, Host, and Env

The .standaloneServer (opens in a new tab) function can take specified:

Port number (port)
  • Must be a valid port number and an Integer
  • Defaults to 4000
try server.standaloneServer(
    port: 8080
)
Hostname (host)
  • Must be a String containing either an IP address or "localhost"
  • Defaults to 127.0.0.1
try server.standaloneServer(
    host: "0.0.0.0"
)
Environment mode (env)
  • Must be either "development", "testing", "production", "dev", "prod", or "test".
try server.standaloneServer(
    env: "production"
)
More info on environment mode

CORS

Given that the standalone option is responsible setup the server, any middleware need to be configured by the function.

To allow CORS using a middleware, .standaloneServer (opens in a new tab) function can take specified CORSMiddleware.Configuration (opens in a new tab).

try server.standaloneServer(
    port: 443,
    host: "0.0.0.0",
    env: "production",
    cors: .init(
        allowedOrigin: .all,
        allowedMethods: [.GET, .POST, .OPTIONS],
        allowedHeaders: [.accept, .authorization, .contentType, .origin, .xRequestedWith, .userAgent, .accessControlAllowOrigin]
    )  
)

Context

Configuring context with the standalone server is identical with the Vapor integration.

Last updated on December 11, 2022