fix: fixed install route (#2064)

This commit is contained in:
Wyatt Johnson
2018-11-06 16:28:04 +00:00
committed by GitHub
parent ca12b73b55
commit 3f949b3712
4 changed files with 15 additions and 10 deletions
+5 -7
View File
@@ -10712,8 +10712,11 @@
"resolved": "https://registry.npmjs.org/fluent-intl-polyfill/-/fluent-intl-polyfill-0.1.0.tgz",
"integrity": "sha1-ETOUSrJHeINHOZVZaIPg05z4hc8=",
"dev": true,
"requires": {
"intl-pluralrules": "github:projectfluent/IntlPluralRules#94cb0fa1c23ad943bc5aafef43cea132fa51d68b"
"dependencies": {
"intl-pluralrules": {
"version": "github:projectfluent/IntlPluralRules#94cb0fa1c23ad943bc5aafef43cea132fa51d68b",
"from": "github:projectfluent/IntlPluralRules#94cb0fa1c23ad943bc5aafef43cea132fa51d68b"
}
}
},
"fluent-langneg": {
@@ -13381,11 +13384,6 @@
"integrity": "sha1-ftGxQQxqDg94z5XTuEQMY/eLhhQ=",
"dev": true
},
"intl-pluralrules": {
"version": "github:projectfluent/IntlPluralRules#94cb0fa1c23ad943bc5aafef43cea132fa51d68b",
"from": "github:projectfluent/IntlPluralRules#module",
"dev": true
},
"invariant": {
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/invariant/-/invariant-2.2.4.tgz",
+3 -2
View File
@@ -14,12 +14,13 @@ import { Request, RequestHandler } from "talk-server/types/express";
* cspMiddleware handles adding the CSP middleware to each outgoing request.
*/
export const cspTenantMiddleware: RequestHandler = (req, res, next) => {
const tenant = req.talk!.tenant;
if (!tenant) {
if (!req.talk || !req.talk.tenant) {
// There is no tenant for the request, don't add any headers.
return next();
}
const tenant = req.talk.tenant;
res.setHeader(
"Content-Security-Policy",
generateContentSecurityPolicy(req, tenant)
+6
View File
@@ -3,15 +3,21 @@ import { RequestHandler } from "talk-server/types/express";
export interface MiddlewareOptions {
cache: TenantCache;
passNoTenant?: boolean;
}
export const tenantMiddleware = ({
cache,
passNoTenant = false,
}: MiddlewareOptions): RequestHandler => async (req, res, next) => {
try {
// Attach the tenant to the request.
const tenant = await cache.retrieveByDomain(req.hostname);
if (!tenant) {
if (passNoTenant) {
return next();
}
// TODO: send a http.StatusNotFound?
return next(new Error("tenant not found"));
}
+1 -1
View File
@@ -23,7 +23,7 @@ export async function createRouter(app: AppOptions, options: RouterOptions) {
attachGraphiQL(router, app);
}
router.use(tenantMiddleware({ cache: app.tenantCache }));
router.use(tenantMiddleware({ cache: app.tenantCache, passNoTenant: true }));
router.use(cspTenantMiddleware);
const staticURI = app.config.get("static_uri");