feat: support development url's

This commit is contained in:
Wyatt Johnson
2018-10-29 14:31:35 -06:00
parent 6fc2eabc88
commit 2571f048ad
8 changed files with 26 additions and 12 deletions
@@ -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,
+1 -5
View File
@@ -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,
+6 -1
View File
@@ -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;
}