Skip to content

Commit 5817231

Browse files
[node-headless-ssr-proxy] [node-headless-ssr-experience-edge] Provide ability to use .env (#977)
* Created a .env file with all the variables we pull from process.env in the config.js file (with empty values). Added the dotenv package to load the variables from the .env file. * Implemented the same changes to node-headless-ssr-experience-edge template. Added the require(dotenv).config() to the app entry points (index.js). * Added comments on how to use the feature and changed .env files to .env.example * Revert "Added comments on how to use the feature and changed .env files to .env.example" This reverts commit 52bb689. * Added PORT variable to node-headless-ssr-proxy/.env * Created a .env file with all the variables we pull from process.env (with empty values). Added the dotenv package to load the variables from the .env file. Calling the dotenv config() in the index.js. * Added new line at the end to node-headless-ssr-experience-edge/.env
1 parent 77f1658 commit 5817231

File tree

7 files changed

+38
-18
lines changed

7 files changed

+38
-18
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
SITECORE_JSS_APP_NAME=
2+
SITECORE_JSS_SERVER_BUNDLE=
3+
SITECORE_EXPERIENCE_EDGE_ENDPOINT=
4+
SITECORE_API_KEY=
5+
PORT=
6+
DEFAULT_LANGUAGE=

packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/index.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
const express = require('express');
22
const compression = require('compression');
3+
require('dotenv').config();
34
const { GraphQLLayoutService } = require('@sitecore-jss/sitecore-jss/layout');
4-
const { GraphQLDictionaryService} = require('@sitecore-jss/sitecore-jss/i18n');
5+
const { GraphQLDictionaryService } = require('@sitecore-jss/sitecore-jss/i18n');
56
const config = require('./config');
67

78
const server = express();
@@ -89,7 +90,9 @@ server.use(async (req, res) => {
8990

9091
const viewBag = { dictionary: {} };
9192

92-
viewBag.dictionary = await dictionaryService.fetchDictionaryData(layoutData.sitecore.context.language);
93+
viewBag.dictionary = await dictionaryService.fetchDictionaryData(
94+
layoutData.sitecore.context.language
95+
);
9396

9497
renderView(
9598
(err, result) => {

packages/create-sitecore-jss/src/templates/node-headless-ssr-experience-edge/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"dependencies": {
2727
"@sitecore-jss/sitecore-jss": "^21.0.0-canary",
2828
"compression": "^1.7.4",
29-
"express": "^4.17.1"
29+
"express": "^4.17.1",
30+
"dotenv": "^16.0.0"
3031
},
3132
"private": true
3233
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
SITECORE_JSS_APP_NAME=
2+
SITECORE_JSS_SERVER_BUNDLE=
3+
SITECORE_API_HOST=
4+
SITECORE_API_KEY=
5+
SITECORE_LAYOUT_SERVICE_ROUTE=
6+
SITECORE_PATH_REWRITE_EXCLUDE_ROUTES=
7+
SITECORE_ENABLE_DEBUG=
8+
PORT=

packages/create-sitecore-jss/src/templates/node-headless-ssr-proxy/config.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const fs = require('fs');
22
const { RestDictionaryService } = require('@sitecore-jss/sitecore-jss/i18n');
3-
const httpAgents = require("./httpAgents");
3+
const httpAgents = require('./httpAgents');
44

55
/**
66
* The JSS application name defaults to providing part of the bundle path as well as the dictionary service endpoint.
@@ -17,7 +17,7 @@ const serverBundle = require(bundlePath);
1717

1818
httpAgents.setUpDefaultAgents(serverBundle);
1919

20-
const apiHost = process.env.SITECORE_API_HOST || 'http://my.sitecore.host'
20+
const apiHost = process.env.SITECORE_API_HOST || 'http://my.sitecore.host';
2121

2222
appName = appName || serverBundle.appName;
2323

@@ -96,16 +96,16 @@ const config = {
9696
// when proxying to a SSL Sitecore instance.
9797
// This is a major security issue, so NEVER EVER set this to false
9898
// outside local development. Use a real CA-issued certificate.
99-
secure: true,
100-
xfwd: true
101-
},
102-
/**
103-
* Custom headers handling.
104-
* You can remove different headers from proxy response.
105-
*/
106-
setHeaders: (req, serverRes, proxyRes) => {
107-
delete proxyRes.headers['content-security-policy'];
108-
},
99+
secure: true,
100+
xfwd: true,
101+
},
102+
/**
103+
* Custom headers handling.
104+
* You can remove different headers from proxy response.
105+
*/
106+
setHeaders: (req, serverRes, proxyRes) => {
107+
delete proxyRes.headers['content-security-policy'];
108+
},
109109
/**
110110
* Custom error handling in case our app fails to render.
111111
* Return null to pass through server response, or { content, statusCode }
@@ -139,7 +139,7 @@ const config = {
139139
return {};
140140
}
141141

142-
return dictionaryService.fetchDictionaryData(language).then(phrases => {
142+
return dictionaryService.fetchDictionaryData(language).then((phrases) => {
143143
const viewBag = {
144144
dictionary: phrases,
145145
};

packages/create-sitecore-jss/src/templates/node-headless-ssr-proxy/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const express = require('express');
22
const compression = require('compression');
3+
require('dotenv').config();
34
const scProxy = require('@sitecore-jss/sitecore-jss-proxy').default;
45
const config = require('./config');
56
const cacheMiddleware = require('./cacheMiddleware');
@@ -38,7 +39,7 @@ server.use((req, res, next) => {
3839
}
3940

4041
next();
41-
})
42+
});
4243

4344
// For any other requests, we render app routes server-side and return them
4445
server.use('*', scProxy(config.serverBundle.renderView, config, config.serverBundle.parseRouteUrl));

packages/create-sitecore-jss/src/templates/node-headless-ssr-proxy/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"agentkeepalive": "^4.1.3",
3030
"compression": "~1.7.3",
3131
"express": "~4.16.4",
32-
"memory-cache": "^0.2.0"
32+
"memory-cache": "^0.2.0",
33+
"dotenv": "^16.0.0"
3334
},
3435
"private": true
3536
}

0 commit comments

Comments
 (0)