#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()
1
2
3
4
5
6
7
8
9
10
11

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

Port number (port)
  • Must be a valid port number and an Integer
  • Defaults to 4000
try server.standaloneServer( port: 8080 )
1
2
3
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" )
1
2
3
Environment mode (env)
  • Must be either "development", "testing", "production", "dev", "prod", or "test".
try server.standaloneServer( env: "production" )
1
2
3

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] ) )
1
2
3
4
5
6
7
8
9
10

#Context

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

Context
../vapor/#context