mirror of
https://github.com/wassname/talk.git
synced 2026-09-12 13:01:11 +08:00
feat: support development url's
This commit is contained in:
@@ -2,6 +2,7 @@ import { RequestHandler } from "express-jwt";
|
||||
import { Redis } from "ioredis";
|
||||
import { Db } from "mongodb";
|
||||
|
||||
import { Config } from "talk-common/config";
|
||||
import TenantContext from "talk-server/graph/tenant/context";
|
||||
import { TaskQueue } from "talk-server/services/queue";
|
||||
import { Request } from "talk-server/types/express";
|
||||
@@ -10,12 +11,14 @@ export interface TenantContextMiddlewareOptions {
|
||||
mongo: Db;
|
||||
redis: Redis;
|
||||
queue: TaskQueue;
|
||||
config: Config;
|
||||
}
|
||||
|
||||
export const tenantContext = ({
|
||||
mongo,
|
||||
redis,
|
||||
queue,
|
||||
config,
|
||||
}: TenantContextMiddlewareOptions): RequestHandler => (
|
||||
req: Request,
|
||||
res,
|
||||
@@ -38,6 +41,7 @@ export const tenantContext = ({
|
||||
req.talk.context = {
|
||||
tenant: new TenantContext({
|
||||
req,
|
||||
config,
|
||||
mongo,
|
||||
redis,
|
||||
tenant,
|
||||
|
||||
@@ -42,11 +42,7 @@ export async function createTenantRouter(
|
||||
// Any users may submit their GraphQL requests with authentication, this
|
||||
// middleware will unpack their user into the request.
|
||||
options.passport.authenticate("jwt", { session: false }),
|
||||
tenantContext({
|
||||
mongo: app.mongo,
|
||||
redis: app.redis,
|
||||
queue: app.queue,
|
||||
}),
|
||||
tenantContext(app),
|
||||
await tenantGraphMiddleware({
|
||||
schema: app.schemas.tenant,
|
||||
config: app.config,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { Config } from "talk-common/config";
|
||||
import { Tenant } from "talk-server/models/tenant";
|
||||
import { Request } from "talk-server/types/express";
|
||||
import { URL } from "url";
|
||||
@@ -16,10 +17,14 @@ export function reconstructURL(req: Request, path: string = "/"): string {
|
||||
* reconstructTenantURL will reconstruct a URL based off of the Tenant's domain.
|
||||
*/
|
||||
export function reconstructTenantURL(
|
||||
config: Config,
|
||||
tenant: Pick<Tenant, "domain">,
|
||||
path: string = "/"
|
||||
): string {
|
||||
const url = new URL(path, `https://${tenant.domain}`);
|
||||
let url: URL = new URL(path, `https://${tenant.domain}`);
|
||||
if (config.get("env") === "development") {
|
||||
url = new URL(path, `http://${tenant.domain}:${config.get("port")}`);
|
||||
}
|
||||
|
||||
return url.href;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user