@sitecore-jss/sitecore-jss-proxy
Advanced tools
Comparing version 22.2.0-canary.39 to 22.2.0-canary.40
@@ -18,2 +18,3 @@ "use strict"; | ||
const config_1 = require("./config"); | ||
const render_1 = require("./render"); | ||
/** | ||
@@ -44,15 +45,13 @@ * Default endpoints for editing requests | ||
sitecore_jss_1.debug.editing('invalid origin host - set allowed origins in JSS_ALLOWED_ORIGINS environment variable'); | ||
return res.status(401).json({ | ||
html: `<html><body>Requests from origin ${(_a = req.headers) === null || _a === void 0 ? void 0 : _a.origin} not allowed</body></html>`, | ||
}); | ||
return res.status(401).send(`Requests from origin ${(_a = req.headers) === null || _a === void 0 ? void 0 : _a.origin} are not allowed`); | ||
} | ||
if (!secret) { | ||
sitecore_jss_1.debug.editing('missing editing secret - set JSS_EDITING_SECRET environment variable'); | ||
return res.status(401).json({ | ||
html: '<html><body>Missing editing secret - set JSS_EDITING_SECRET environment variable</body></html>', | ||
}); | ||
return res | ||
.status(401) | ||
.send('Missing editing secret - set JSS_EDITING_SECRET environment variable'); | ||
} | ||
if (secret !== providedSecret) { | ||
sitecore_jss_1.debug.editing('invalid editing secret - sent "%s" expected "%s"', secret, providedSecret); | ||
return res.status(401).json({ html: '<html><body>Missing or invalid secret</body></html>' }); | ||
sitecore_jss_1.debug.editing('invalid editing secret - sent "%s" expected "%s"', providedSecret, secret); | ||
return res.status(401).send('Missing or invalid secret'); | ||
} | ||
@@ -69,5 +68,3 @@ return next(); | ||
sitecore_jss_1.debug.editing('invalid method or path - sent %s %s', req.method, req.originalUrl); | ||
return res.status(405).json({ | ||
html: `<html><body>Invalid request method or path ${req.method} ${req.originalUrl}</body></html>`, | ||
}); | ||
return res.status(405).send(`Invalid request method or path ${req.method} ${req.originalUrl}`); | ||
}; | ||
@@ -83,9 +80,6 @@ /** | ||
const editingRouter = (options) => { | ||
var _a; | ||
const router = (0, express_1.Router)(); | ||
router.use(exports.editingMiddleware); | ||
router.get(options.config.path || ENDPOINTS.CONFIG, (0, config_1.editingConfigMiddleware)(options.config)); | ||
router.get(((_a = options.render) === null || _a === void 0 ? void 0 : _a.path) || ENDPOINTS.RENDER, () => { | ||
return null; | ||
}); | ||
router.get(options.render.path || ENDPOINTS.RENDER, (0, render_1.editingRenderMiddleware)(options.render)); | ||
router.use(editingNotFoundMiddleware); | ||
@@ -92,0 +86,0 @@ return router; |
@@ -15,2 +15,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import { editingConfigMiddleware } from './config'; | ||
import { editingRenderMiddleware } from './render'; | ||
/** | ||
@@ -41,15 +42,13 @@ * Default endpoints for editing requests | ||
debug.editing('invalid origin host - set allowed origins in JSS_ALLOWED_ORIGINS environment variable'); | ||
return res.status(401).json({ | ||
html: `<html><body>Requests from origin ${(_a = req.headers) === null || _a === void 0 ? void 0 : _a.origin} not allowed</body></html>`, | ||
}); | ||
return res.status(401).send(`Requests from origin ${(_a = req.headers) === null || _a === void 0 ? void 0 : _a.origin} are not allowed`); | ||
} | ||
if (!secret) { | ||
debug.editing('missing editing secret - set JSS_EDITING_SECRET environment variable'); | ||
return res.status(401).json({ | ||
html: '<html><body>Missing editing secret - set JSS_EDITING_SECRET environment variable</body></html>', | ||
}); | ||
return res | ||
.status(401) | ||
.send('Missing editing secret - set JSS_EDITING_SECRET environment variable'); | ||
} | ||
if (secret !== providedSecret) { | ||
debug.editing('invalid editing secret - sent "%s" expected "%s"', secret, providedSecret); | ||
return res.status(401).json({ html: '<html><body>Missing or invalid secret</body></html>' }); | ||
debug.editing('invalid editing secret - sent "%s" expected "%s"', providedSecret, secret); | ||
return res.status(401).send('Missing or invalid secret'); | ||
} | ||
@@ -65,5 +64,3 @@ return next(); | ||
debug.editing('invalid method or path - sent %s %s', req.method, req.originalUrl); | ||
return res.status(405).json({ | ||
html: `<html><body>Invalid request method or path ${req.method} ${req.originalUrl}</body></html>`, | ||
}); | ||
return res.status(405).send(`Invalid request method or path ${req.method} ${req.originalUrl}`); | ||
}; | ||
@@ -79,11 +76,8 @@ /** | ||
export const editingRouter = (options) => { | ||
var _a; | ||
const router = Router(); | ||
router.use(editingMiddleware); | ||
router.get(options.config.path || ENDPOINTS.CONFIG, editingConfigMiddleware(options.config)); | ||
router.get(((_a = options.render) === null || _a === void 0 ? void 0 : _a.path) || ENDPOINTS.RENDER, () => { | ||
return null; | ||
}); | ||
router.get(options.render.path || ENDPOINTS.RENDER, editingRenderMiddleware(options.render)); | ||
router.use(editingNotFoundMiddleware); | ||
return router; | ||
}; |
{ | ||
"name": "@sitecore-jss/sitecore-jss-proxy", | ||
"version": "22.2.0-canary.39", | ||
"version": "22.2.0-canary.40", | ||
"description": "Middlewares, utilities to work in a headless mode", | ||
@@ -12,3 +12,3 @@ "main": "dist/cjs/index.js", | ||
"lint": "eslint \"./src/**/*.ts\"", | ||
"test": "mocha --require ts-node/register \"./src/**/*.test.ts\"", | ||
"test": "mocha --require ts-node/register \"./src/**/*.test.ts\" --exit", | ||
"prepublishOnly": "npm run build", | ||
@@ -31,3 +31,3 @@ "coverage": "nyc npm test", | ||
"dependencies": { | ||
"@sitecore-jss/sitecore-jss": "^22.2.0-canary.39", | ||
"@sitecore-jss/sitecore-jss": "^22.2.0-canary.40", | ||
"http-proxy-middleware": "^2.0.6", | ||
@@ -43,2 +43,3 @@ "http-status-codes": "^2.2.0", | ||
"@types/set-cookie-parser": "^2.4.2", | ||
"@types/sinon": "^17.0.3", | ||
"@types/supertest": "^6.0.2", | ||
@@ -51,2 +52,3 @@ "chai": "^4.3.7", | ||
"nyc": "^15.1.0", | ||
"sinon": "^17.0.1", | ||
"supertest": "^7.0.0", | ||
@@ -60,3 +62,3 @@ "ts-node": "^10.9.1", | ||
"types": "types/index.d.ts", | ||
"gitHead": "b4f4b36dd7b9b0aadabfeca4c8886ca3db8cfec5", | ||
"gitHead": "5df1777482a509977ed6b3273e7eef6e3053869f", | ||
"files": [ | ||
@@ -63,0 +65,0 @@ "dist", |
@@ -1,2 +0,2 @@ | ||
import { RequestHandler } from 'express'; | ||
import { Request, Response } from 'express'; | ||
import { Metadata } from '@sitecore-jss/sitecore-jss/utils'; | ||
@@ -27,2 +27,2 @@ /** | ||
*/ | ||
export declare const editingConfigMiddleware: (config: EditingConfigEndpointOptions) => RequestHandler; | ||
export declare const editingConfigMiddleware: (config: EditingConfigEndpointOptions) => (_req: Request, res: Response) => void; |
import { NextFunction, Request, Response } from 'express'; | ||
import { EditingConfigEndpointOptions } from './config'; | ||
import { EditingRenderEndpointOptions } from './render'; | ||
/** | ||
@@ -14,8 +15,3 @@ * Configuration for the editing router | ||
*/ | ||
render?: { | ||
/** | ||
* Custom path for the editing render endpoint | ||
*/ | ||
path?: string; | ||
}; | ||
render: EditingRenderEndpointOptions; | ||
}; | ||
@@ -22,0 +18,0 @@ /** |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
88864
36
1647
17