mirror of
https://github.com/wassname/talk.git
synced 2026-06-27 20:23:30 +08:00
fix: fixed install route (#2064)
This commit is contained in:
Generated
+5
-7
@@ -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",
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user