Skip to content

Commit

Permalink
feat: remove old unused field staplerUrl from local server
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxGenash committed Mar 30, 2021
1 parent eaff7ee commit a3ec69f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 34 deletions.
25 changes: 8 additions & 17 deletions lib/stencil-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ class StencilStart {
// Use initial (before updates) port for BrowserSync
const browserSyncPort = initialStencilConfig.port;

const storeInfoFromAPI = await this.runAPICheck(initialStencilConfig, stencilCliVersion);
const storeInfoFromAPI = await this.runAPICheck(
initialStencilConfig.normalStoreUrl,
stencilCliVersion,
);
const updatedStencilConfig = this.updateStencilConfig(
initialStencilConfig,
storeInfoFromAPI,
Expand Down Expand Up @@ -88,24 +91,16 @@ class StencilStart {

/**
*
* @param {object} stencilConfig
* @param {string} storeUrl
* @param {string} currentCliVersion
* @returns {Promise<object>}
*/
async runAPICheck(stencilConfig, currentCliVersion) {
const staplerUrl = stencilConfig.staplerUrl
? stencilConfig.staplerUrl
: stencilConfig.normalStoreUrl;
const url = new URL(`/stencil-version-check?v=${currentCliVersion}`, staplerUrl).toString();
async runAPICheck(storeUrl, currentCliVersion) {
const url = new URL(`/stencil-version-check?v=${currentCliVersion}`, storeUrl).toString();
let payload;

const headers = {};
if (stencilConfig.staplerUrl) {
headers['stencil-store-url'] = stencilConfig.normalStoreUrl;
}

try {
const response = await this._networkUtils.sendApiRequest({ url, headers });
const response = await this._networkUtils.sendApiRequest({ url });
payload = response.data;
if (!payload) {
throw new Error('Empty payload in the server response');
Expand Down Expand Up @@ -275,10 +270,6 @@ class StencilStart {
information += `config.json location: ${this._themeConfigManager.configPath.cyan}\n`;
information += `Store URL: ${stencilConfig.normalStoreUrl.cyan}\n`;

if (stencilConfig.staplerUrl) {
information += `Stapler URL: ${stencilConfig.staplerUrl.cyan}\n`;
}

information += `SSL Store URL: ${stencilConfig.storeUrl.cyan}\n`;
information += `Node Version: ${process.version.cyan}\n`;
information += '\n';
Expand Down
1 change: 0 additions & 1 deletion server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ function buildManifest(srcManifest, options) {
parsedNormalUrl.protocol + '//' + parsedNormalUrl.host;
pluginsByName['./plugins/router/router.module'].apiKey = options.dotStencilFile.apiKey;
pluginsByName['./plugins/router/router.module'].port = options.dotStencilFile.port;
pluginsByName['./plugins/router/router.module'].staplerUrl = options.dotStencilFile.staplerUrl;
pluginsByName['./plugins/renderer/renderer.module'].useCache = options.useCache;
pluginsByName['./plugins/renderer/renderer.module'].username = options.dotStencilFile.username;
pluginsByName['./plugins/renderer/renderer.module'].token = options.dotStencilFile.token;
Expand Down
22 changes: 8 additions & 14 deletions server/plugins/renderer/renderer.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,18 @@ internals.sha1sum = (input) => {
* @param request
*/
internals.getResponse = async (request) => {
const staplerUrlObject = request.app.staplerUrl
? new URL(request.app.staplerUrl)
: new URL(request.app.storeUrl);
const storeUrlObj = new URL(request.app.storeUrl);

const httpOpts = {
url: Object.assign(new URL(request.url.toString()), {
port: staplerUrlObject.port,
host: staplerUrlObject.host,
protocol: staplerUrlObject.protocol,
port: storeUrlObj.port,
host: storeUrlObj.host,
protocol: storeUrlObj.protocol,
}).toString(),
headers: internals.buildReqHeaders({
request,
stencilOptions: { get_template_file: true, get_data_only: true },
extraHeaders: { host: staplerUrlObject.host },
extraHeaders: { host: storeUrlObj.host },
}),
accessToken: internals.options.accessToken,
data: request.payload,
Expand All @@ -88,7 +86,7 @@ internals.getResponse = async (request) => {

const responseArgs = {
httpOpts,
staplerUrlObject,
storeUrlObj,
};

// check request signature and use cache, if available
Expand Down Expand Up @@ -148,7 +146,7 @@ internals.getResponse = async (request) => {
* @returns {*}
*/
internals.parseResponse = async (bcAppData, request, response, responseArgs) => {
const { httpOpts, staplerUrlObject } = responseArgs;
const { httpOpts, storeUrlObj } = responseArgs;

if (typeof bcAppData !== 'object' || !('pencil_response' in bcAppData)) {
delete response.headers['x-frame-options'];
Expand All @@ -169,7 +167,7 @@ internals.parseResponse = async (bcAppData, request, response, responseArgs) =>
request,
stencilOptions: { get_data_only: true },
stencilConfig: internals.getResourceConfig(bcAppData, request, configuration),
extraHeaders: { host: staplerUrlObject.host },
extraHeaders: { host: storeUrlObj.host },
});
httpOpts.responseType = 'json'; // In the second request we always expect json

Expand Down Expand Up @@ -386,10 +384,6 @@ internals.buildReqHeaders = ({
if (!request.headers['stencil-config'] && stencilConfig) {
headers['stencil-config'] = JSON.stringify(stencilConfig);
}
// Development
if (request.app.staplerUrl) {
headers['stencil-store-url'] = request.app.storeUrl;
}

return { ...request.headers, ...headers, ...extraHeaders };
};
Expand Down
2 changes: 0 additions & 2 deletions server/plugins/router/router.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const internals = {
options: {
storeUrl: '',
apiKey: '',
staplerUrl: '',
port: '',
},
paths: {
Expand All @@ -27,7 +26,6 @@ function register(server, options) {
request.app.storeUrl = internals.options.storeUrl;
request.app.normalStoreUrl = internals.options.normalStoreUrl;
request.app.apiKey = internals.options.apiKey;
request.app.staplerUrl = internals.options.staplerUrl;
request.app.themeConfig = ThemeConfig.getInstance();

return h.continue;
Expand Down

0 comments on commit a3ec69f

Please sign in to comment.