mirror of
https://github.com/wassname/talk.git
synced 2026-08-04 13:23:35 +08:00
* feat: added graphqlBatch * refactor: cleanup of json serial * refactor: cleanup of json serilization * feat: use react network layer * fix: adjusted broken user * fix: temporarily disable cache for profile query * test: temporarily use precompiled modules * fix: bug when updating comment count on an asset * fix: compile modules to commonjs for jest * test: add react-relay-network-layer to transform whitelist * fix: use react-relay-network-layer/es * types: add react-relay-network-modern typescript types * feat: integrate custom error middleware * review: add todo
41 lines
903 B
TypeScript
41 lines
903 B
TypeScript
import { RequestHandler } from "express";
|
|
|
|
import TenantCache from "talk-server/services/tenant/cache";
|
|
import { Request } from "talk-server/types/express";
|
|
|
|
export interface MiddlewareOptions {
|
|
cache: TenantCache;
|
|
}
|
|
|
|
export default ({ cache }: MiddlewareOptions): RequestHandler => async (
|
|
req: Request,
|
|
res,
|
|
next
|
|
) => {
|
|
try {
|
|
// 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"));
|
|
}
|
|
|
|
// Set Talk on the request.
|
|
req.talk = {
|
|
cache: {
|
|
// Attach the tenant cache to the request.
|
|
tenant: cache,
|
|
},
|
|
// Attach the tenant to the request.
|
|
tenant,
|
|
};
|
|
|
|
// Attach the tenant to the view locals.
|
|
res.locals.tenant = tenant;
|
|
|
|
next();
|
|
} catch (err) {
|
|
next(err);
|
|
}
|
|
};
|