# 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.

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 function can take specified:

  • Must be a valid port number and an Integer
  • Defaults to 4000
try server.standaloneServer(
    port: 8080
)
  • 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"
)
  • 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 function can take specified CORSMiddleware.Configuration.

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.

Context
../vapor/#context