Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[node-headless-ssr-proxy] [node-headless-ssr-experience-edge] Provide ability to use .env #977

Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SITECORE_JSS_APP_NAME=
SITECORE_JSS_SERVER_BUNDLE=
SITECORE_EXPERIENCE_EDGE_ENDPOINT=
SITECORE_API_KEY=
PORT=
DEFAULT_LANGUAGE=
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const express = require('express');
const compression = require('compression');
require('dotenv').config();
const { GraphQLLayoutService } = require('@sitecore-jss/sitecore-jss/layout');
const { GraphQLDictionaryService} = require('@sitecore-jss/sitecore-jss/i18n');
const { GraphQLDictionaryService } = require('@sitecore-jss/sitecore-jss/i18n');
const config = require('./config');

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

const viewBag = { dictionary: {} };

viewBag.dictionary = await dictionaryService.fetchDictionaryData(layoutData.sitecore.context.language);
viewBag.dictionary = await dictionaryService.fetchDictionaryData(
layoutData.sitecore.context.language
);

renderView(
(err, result) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"dependencies": {
"@sitecore-jss/sitecore-jss": "^21.0.0-canary",
"compression": "^1.7.4",
"express": "^4.17.1"
"express": "^4.17.1",
"dotenv": "^16.0.0"
},
"private": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
SITECORE_JSS_APP_NAME=
SITECORE_JSS_SERVER_BUNDLE=
SITECORE_API_HOST=
SITECORE_API_KEY=
SITECORE_LAYOUT_SERVICE_ROUTE=
SITECORE_PATH_REWRITE_EXCLUDE_ROUTES=
SITECORE_ENABLE_DEBUG=
PORT=
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require('fs');
const { RestDictionaryService } = require('@sitecore-jss/sitecore-jss/i18n');
const httpAgents = require("./httpAgents");
const httpAgents = require('./httpAgents');

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

httpAgents.setUpDefaultAgents(serverBundle);

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

appName = appName || serverBundle.appName;

Expand Down Expand Up @@ -96,16 +96,16 @@ const config = {
// when proxying to a SSL Sitecore instance.
// This is a major security issue, so NEVER EVER set this to false
// outside local development. Use a real CA-issued certificate.
secure: true,
xfwd: true
},
/**
* Custom headers handling.
* You can remove different headers from proxy response.
*/
setHeaders: (req, serverRes, proxyRes) => {
delete proxyRes.headers['content-security-policy'];
},
secure: true,
xfwd: true,
},
/**
* Custom headers handling.
* You can remove different headers from proxy response.
*/
setHeaders: (req, serverRes, proxyRes) => {
delete proxyRes.headers['content-security-policy'];
},
/**
* Custom error handling in case our app fails to render.
* Return null to pass through server response, or { content, statusCode }
Expand Down Expand Up @@ -139,7 +139,7 @@ const config = {
return {};
}

return dictionaryService.fetchDictionaryData(language).then(phrases => {
return dictionaryService.fetchDictionaryData(language).then((phrases) => {
const viewBag = {
dictionary: phrases,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const express = require('express');
const compression = require('compression');
require('dotenv').config();
const scProxy = require('@sitecore-jss/sitecore-jss-proxy').default;
const config = require('./config');
const cacheMiddleware = require('./cacheMiddleware');
Expand Down Expand Up @@ -38,7 +39,7 @@ server.use((req, res, next) => {
}

next();
})
});

// For any other requests, we render app routes server-side and return them
server.use('*', scProxy(config.serverBundle.renderView, config, config.serverBundle.parseRouteUrl));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"agentkeepalive": "^4.1.3",
"compression": "~1.7.3",
"express": "~4.16.4",
"memory-cache": "^0.2.0"
"memory-cache": "^0.2.0",
"dotenv": "^16.0.0"
},
"private": true
}