@@ -4,20 +4,27 @@ const { getEnv } = require('./utils/env');
44
55function createAposConfig ( ) {
66 const isProduction = process . env . NODE_ENV === 'production' ;
7- const baseUrl = getEnv ( 'BASE_URL' ) || ( isProduction ? 'https://speedandfunction.com' : 'http://localhost:3000' ) ;
8-
7+ let baseUrl = getEnv ( 'BASE_URL' ) ;
8+ if ( ! baseUrl ) {
9+ if ( isProduction ) {
10+ baseUrl = 'https://speedandfunction.com' ;
11+ } else {
12+ baseUrl = 'http://localhost:3000' ;
13+ }
14+ }
15+
916 return {
1017 shortName : 'apostrophe-site' ,
11- baseUrl : baseUrl ,
12-
18+ baseUrl,
19+
1320 // Session configuration
1421 modules : {
1522 // Core modules configuration
1623 '@apostrophecms/express' : {
1724 options : {
1825 // Trust proxy for Railway deployment
1926 trustProxy : true ,
20-
27+
2128 session : {
2229 // If using Redis (recommended for production)
2330 secret : getEnv ( 'SESSION_SECRET' ) ,
@@ -27,70 +34,93 @@ function createAposConfig() {
2734 url : getEnv ( 'REDIS_URI' ) ,
2835 } ,
2936 } ,
30- cookie : {
37+ cookie : ( ( ) => {
38+ const cookieConfig = {
39+ secure : isProduction ,
40+ sameSite : 'lax' ,
41+ httpOnly : true ,
42+ // 24 hours
43+ maxAge : 24 * 60 * 60 * 1000 ,
44+ } ;
3145 // Set domain for production to work with custom domain
32- domain : isProduction ? '.speedandfunction.com' : undefined ,
33- secure : isProduction ,
34- sameSite : 'lax' ,
35- httpOnly : true ,
36- maxAge : 24 * 60 * 60 * 1000 , // 24 hours
37- } ,
46+ if ( isProduction ) {
47+ cookieConfig . domain = '.speedandfunction.com' ;
48+ }
49+ return cookieConfig ;
50+ } ) ( ) ,
3851 } ,
39-
52+
4053 csrf : {
41- cookie : {
42- key : '_csrf' ,
43- path : '/' ,
44- httpOnly : true ,
45- secure : isProduction ,
46- sameSite : 'lax' ,
47- maxAge : 3600 ,
54+ cookie : ( ( ) => {
55+ const csrfCookieConfig = {
56+ key : '_csrf' ,
57+ path : '/' ,
58+ httpOnly : true ,
59+ secure : isProduction ,
60+ sameSite : 'lax' ,
61+ maxAge : 3600 ,
62+ } ;
4863 // CRITICAL: Set domain for CSRF cookie to work with custom domain
49- domain : isProduction ? '.speedandfunction.com' : undefined ,
50- } ,
64+ if ( isProduction ) {
65+ csrfCookieConfig . domain = '.speedandfunction.com' ;
66+ }
67+ return csrfCookieConfig ;
68+ } ) ( ) ,
5169 // Additional CSRF options for better security
5270 ignoreMethods : [ 'GET' , 'HEAD' , 'OPTIONS' ] ,
5371 value : ( req ) => {
54- return req . body && req . body . _csrf ||
55- req . query && req . query . _csrf ||
56- req . headers [ 'x-csrf-token' ] ||
57- req . headers [ 'x-xsrf-token' ] ||
58- req . headers [ 'csrf-token' ] ;
59- }
72+ const csrfKey = '_csrf' ;
73+ return (
74+ ( req . body && req . body [ csrfKey ] ) ||
75+ ( req . query && req . query [ csrfKey ] ) ||
76+ req . headers [ 'x-csrf-token' ] ||
77+ req . headers [ 'x-xsrf-token' ] ||
78+ req . headers [ 'csrf-token' ]
79+ ) ;
80+ } ,
6081 } ,
61-
82+
6283 // Add middleware to handle domain-specific headers
6384 middleware : [
6485 {
6586 before : '@apostrophecms/csrf' ,
6687 middleware : ( req , res , next ) => {
6788 // Ensure proper headers for custom domain
68- if ( req . hostname === 'speedandfunction.com' || req . get ( 'host' ) === 'speedandfunction.com' ) {
89+ if (
90+ req . hostname === 'speedandfunction.com' ||
91+ req . get ( 'host' ) === 'speedandfunction.com'
92+ ) {
6993 req . headers [ 'x-forwarded-host' ] = 'speedandfunction.com' ;
7094 req . headers [ 'x-forwarded-proto' ] = 'https' ;
7195 }
72-
96+
7397 // Set CORS headers for API requests
7498 const allowedOrigins = [
7599 'https://speedandfunction.com' ,
76- 'https://apostrophe-cms-production.up.railway.app'
100+ 'https://apostrophe-cms-production.up.railway.app' ,
77101 ] ;
78-
79- const origin = req . headers . origin ;
102+
103+ const { origin } = req . headers ;
80104 if ( allowedOrigins . includes ( origin ) ) {
81105 res . setHeader ( 'Access-Control-Allow-Origin' , origin ) ;
82106 res . setHeader ( 'Access-Control-Allow-Credentials' , 'true' ) ;
83- res . setHeader ( 'Access-Control-Allow-Methods' , 'GET, POST, PUT, DELETE, OPTIONS' ) ;
84- res . setHeader ( 'Access-Control-Allow-Headers' , 'Origin, X-Requested-With, Content-Type, Accept, Authorization, X-CSRF-Token, X-XSRF-TOKEN' ) ;
107+ res . setHeader (
108+ 'Access-Control-Allow-Methods' ,
109+ 'GET, POST, PUT, DELETE, OPTIONS' ,
110+ ) ;
111+ res . setHeader (
112+ 'Access-Control-Allow-Headers' ,
113+ 'Origin, X-Requested-With, Content-Type, Accept, Authorization, X-CSRF-Token, X-XSRF-TOKEN' ,
114+ ) ;
85115 }
86-
116+
87117 next ( ) ;
88- }
89- }
90- ]
118+ } ,
119+ } ,
120+ ] ,
91121 } ,
92122 } ,
93-
123+
94124 // Make getEnv function available to templates
95125 '@apostrophecms/template' : {
96126 options : {
@@ -99,13 +129,13 @@ function createAposConfig() {
99129 } ,
100130 } ,
101131 } ,
102-
132+
103133 // Add global data module
104134 'global-data' : { } ,
105-
135+
106136 // Shared constants module
107137 '@apostrophecms/shared-constants' : { } ,
108-
138+
109139 // Configure page types
110140 '@apostrophecms/rich-text-widget' : { } ,
111141 '@apostrophecms/image-widget' : {
@@ -119,7 +149,7 @@ function createAposConfig() {
119149 className : 'bp-video-widget' ,
120150 } ,
121151 } ,
122-
152+
123153 // Custom Widgets
124154 'home-hero-widget' : { } ,
125155 'default-hero-widget' : { } ,
@@ -135,7 +165,7 @@ function createAposConfig() {
135165 'contact-widget' : { } ,
136166 'page-intro-widget' : { } ,
137167 'whitespace-widget' : { } ,
138-
168+
139169 // The main form module
140170 '@apostrophecms/form' : { } ,
141171 // The form widget module, allowing editors to add forms to content areas
@@ -144,14 +174,14 @@ function createAposConfig() {
144174 '@apostrophecms/form-text-field-widget' : { } ,
145175 '@apostrophecms/form-textarea-field-widget' : { } ,
146176 '@apostrophecms/form-checkboxes-field-widget' : { } ,
147-
177+
148178 // Custom Pieces
149179 'team-members' : { } ,
150180 'testimonials' : { } ,
151-
181+
152182 // `asset` supports the project"s webpack build for client-side assets.
153183 'asset' : { } ,
154-
184+
155185 // The project"s first custom page type.
156186 'default-page' : { } ,
157187 '@apostrophecms/import-export' : { } ,
@@ -175,4 +205,4 @@ if (require.main === module) {
175205 apostrophe ( createAposConfig ( ) ) ;
176206}
177207
178- module . exports = { createAposConfig } ;
208+ module . exports = { createAposConfig } ;
0 commit comments