/**
 * Server-side Express application
 * - API methods
 * - entry-point to shared React App
 *
 */ import pgConnect from 'connect-pg-simple' ; import express from 'express' ; import session from 'express-session' ; import apiServer from './api/api' ; import db from './db' ; import frontendRoute from './frontendRoute' ; import tileserver from './tiles/tileserver' ; const server = express ( ) ; server . disable ( 'x-powered-by' ) ; server . use ( express . static ( process . env . RAZZLE_PUBLIC_DIR ) ) ; const pgSession = pgConnect ( session ) ; const sess = { name : 'cl.session' , store : new pgSession ( { pgPromise : db , tableName : 'user_sessions' } ) , secret : process . env . APP_COOKIE_SECRET , saveUninitialized : false , resave : false , cookie : { maxAge : 30 * 24 * 60 * 60 * 1000 } } ; if ( server . get ( 'env' ) === 'production' ) { server . set ( 'trust proxy' , 1 ) ; sess . cookie . secure = true ; } server . use ( session ( sess ) ) ; server . use ( '/tiles' , tileserver ) ; server . use ( '/api' , apiServer ) ; server . use ( frontendRoute ) ; export default server ;