Files
talk/src/core/server/app/middleware/tenant.ts
T
Wyatt JohnsonandGitHub d2106b3de5 [next] Templates (#1760)
* feat: initial support for synced tenants

* fix: cleanup

* fix: logger now respects logging level

* fix: cache now ignores updates issued from itself

* feat: print subscriber count

* feat: initial nunjucks support

* fix: support tenant cache for oidc strategy

* fix: replace some constructor initializers with property initializers

* fix: audit

* [next] Comments and Moderation (#1759)

* feat: initial moderation + validation for new comments

* fix: added Promiseable type

* feat: initial actions impl

* feat: more moderation phases

* fix: handle settings inheritence

* fix: moved settings into new file

* fix: defaults and documentation

* fix: replace merge with object spread

* feat: added integration with akismet

* fix: fixed compile

* fix: import ordering

* fix: merge issue causing build to fail

* feat: added gulp, static templates

* fix: added compile step back

* Fix extract css + remove cross-env
2018-08-10 16:17:39 +00:00

39 lines
881 B
TypeScript

import { NextFunction, Response } from "express";
import TenantCache from "talk-server/services/tenant/cache";
import { Request } from "talk-server/types/express";
export interface MiddlewareOptions {
cache: TenantCache;
}
export default (options: MiddlewareOptions) => async (
req: Request,
res: Response,
next: NextFunction
) => {
try {
const { cache } = options;
// Attach the tenant to the request.
const tenant = await cache.retrieveByDomain(req.hostname);
if (!tenant) {
// TODO: send a http.StatusNotFound?
return next(new Error("tenant not found"));
}
// Attach the tenant cache to the request.
req.tenantCache = cache;
// Attach the tenant to the request.
req.tenant = tenant;
// Attach the tenant to the view locals.
res.locals.tenant = tenant;
next();
} catch (err) {
next(err);
}
};