Blueprint
  • Blueprint Developer Guide
  • Quick Start
    • Getting Started
    • My First Application
      • Creating Your Application
      • Controllers
      • Routers & Routes
      • Services
      • Resources & Resource Controllers
      • Validating & Sanitizing Input
      • Unit Testing Your Application
      • Policies
  • Developer Guide
    • The Object Model
      • Introduction
      • Classes and Instances
      • Computed Properties
      • Aggregated Properties
      • Mixins
    • Routers and Controllers
      • Introduction
      • Routers
      • Controllers
      • Resources
    • Models
    • The Server
    • Policy Framework
    • Services
    • Messaging Framework
    • Configuration Management
    • Application and Resources
      • Lookup Operation
      • Views
      • Assets
    • Blueprint Modules
    • Blueprint Cluster
      • What is a Blueprint Cluster?
      • Running a Blueprint Cluster
      • Technical Details
    • Testing Framework
    • Command-line Interface (Coming Soon)
Powered by GitBook
On this page
  • Overview
  • Protocols
  • http
  • https
  • Built-in Middleware
  • Morgan
  • Body Parser
  • Express Validator
  • Configuration
  • Cookie Parser (optional)
  • Express Session (optional)
  • Passport (optional)
  • Custom (optional)
  • Static Files
  1. Developer Guide

The Server

Learn how to configure the server

PreviousModelsNextPolicy Framework

Last updated 7 years ago

Overview

The server is the part of the Blueprint application responsible for handling request. It is essentially a Wrapper Facade for an Express application. The server exists to provide functionality that is common across all Express application, such as listening on ports and . There are no extra steps need to use the server in your Blueprint application. You just need to configure it to meet you needs.

You configure the server using the configuration file named app/config/server.js, or a corresponding configuration file for the node environment.

Protocols

The server natively supports the http and https protocol. You configure the protocols under the protocols section of the server configuration file.

http

Here is an example configuration for http where we are setting the port number. The http hash is the options support for .

app/configs/server.js
module.exports = {
  protocols: {
    http: {
      port: 8080      // default is 80
    }
  }
}

https

app/configs/server.js
module.exports = {
  protocols: {
    https: {
      port: 8443,      // default is 443
      key: blueprint.assetSync ('ssl/server.key'),
      cert: blueprint.assetSync ('ssl/serer.cert')
    }
  }
}

Built-in Middleware

All built-in middleware is configured under the middleware property. If a specific middleware configuration is not defined and it does not have a default configuration, then it is not loaded. The server supports the following Blueprint middleware, in order.

Morgan

Configuration

app/configs/server.js
module.exports = {
  middleware: {
    morgan: {
      // morgan options go here
    }
  }

Body Parser

Configuration

app/config/server.js
module.exports = {
  middleware: {
    bodyParser: {
      json: {
        // add bodyParser.json options here
      },
      
      urlencoded: {
        // add bodyParser.urlencoded options here
      }
    }
  }
}

Express Validator

Configuration

Cookie Parser (optional)

Configuration

app/configs/server.js
module.exports = {
  middleware {
    cookies: {
      secret: 'sshhh',    // secret for signing cookies
      options: { }        // [optional] an object that is passed to cookie.parse
    }  
  }
}

Express Session (optional)

Configuration

app/configs/server.js
module.exports = {
  middleware: {
    session: {
      // Add configuration options here
    }
  }
};

Passport (optional)

Configuration

app/configs/server.js
module.exports = {
  middleware: {
    passport: {
      // optional Passport session configuration
      session: {
        // method for serializing a session to a response
        serializer () {
        
        },
        
        // method for deserializing a session from a request
        deserializer () {
        
        }
      }
    }
  }
}

Custom (optional)

Custom middleware is middleware functions that should be applied the entire application that are not suited for inclusion via a router, and not built-in middleware supported by the server.

Configuration

app/configs/server.js
module.exports = {
  middleware: {
    custom: [ 
      // add middleware functions here
    ]
  }
}

Static Files

Static files are assets on the server that are not dynamically generated. For example, an icon image file, a style sheet, or a javascript file could be considered a static file. The server is not considered with each individual static file, but where the static files reside.

Configuration

You use the static property in the server configuration file to define the location of the static files. The static property takes an array of paths to the static files. If the path is a relative path, then it is is relation the app/ directory. If the path is an absolute path, then the specified path is used as-is.

app/configs/server.js
module.exports = {
  statics: [
    '../public_html',
    '/var/files'
  ]
}

Here is an example configuration for https where we are setting the port number, public key, and private key. The https hash is the options support for .

is http request logging middleware for .

Use middleware.morgan property to configure . If you do not provide a configuration for , then a default one is provided. See the .

is Node.js parsing middleware for . It is responsible for parsing the body of a HTTP request and making the content available on req.body. support different kinds of parsers, such as and .

Use middleware.bodyParser to define the configuration for . Each parser you want to support has a named configuration under middleware.bodyParser. and body parsers are always enabled. You, however, can change the configuration of and body parsers, and include others supported by the middleware.

is middleware for validating the input of an HTTP request. It is does this by adapting into an middleware. is used by to .

There is no configuration support for .

The middleware in responsible for parsing HTTP request cookies and making them available via req.cookies.

Use the middleware.cookies property to configure the middleware. See the documentation for the .

is very simple session middleware for Express. The session information is available on the req.session data property.

Use the middleware.session property to configure the middleware. See the documentation for the .

is authentication middleware for .

Use the middleware.passport data property to configure . If middleware.passport.session is defined in the server configuration file, then the server will .

Use the middleware.custom property to configure custom middleware. The custom.middleware property takes either a , or an array of .

https.createServer
morgan
Express
morgan
morgan
morgan documentation for available options
bodyParser
Express
bodyParser
JSON
url encoded
bodyParser
JSON
url encoded
JSON
url encoded
bodyParser
express-validator
cookie-parser
cookie-parser
cookie-parser
available configuration options
express-session
express-session
express-session
available configuration options
Passport
Node.js
Passport
configure session support with the Passport middleware
single Express middleware function
Express middleware functions
http.createServer
installing middleware in the correct order
express-validator
validator
Express
express-validator
actions
validate and sanitize input