Skip to content

Commit

Permalink
Sync
Browse files Browse the repository at this point in the history
  • Loading branch information
fwang committed Dec 22, 2023
1 parent 768ef2a commit df6d35d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 48 deletions.
8 changes: 7 additions & 1 deletion examples/nextjs/sst.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ export default $config({
};
},
async run() {
const site = new sst.Nextjs("Web");
const site = new sst.Nextjs("Web", {
domain: "ion-next.sst.st",
});

return {
siteURL: site.url,
};
},
});
10 changes: 6 additions & 4 deletions examples/playground/sst.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,23 @@ export default $config({
});

function testProviderOutput() {
interface Random {
num: number;
}

const randomprovider: pulumi.dynamic.ResourceProvider = {
async create(inputs) {
return { id: "foo", outs: { num: "foo" } };
},
};

class Random extends pulumi.dynamic.Resource {
public readonly num!: pulumi.Output<string>;

constructor(name: string, opts?: pulumi.CustomResourceOptions) {
super(randomprovider, name, {}, opts);
super(randomprovider, name, { num: undefined }, opts);
}
}
const random = new Random("Random");
return random.num;
return { r: random.num, r2: "hi" };
}

function testHostedZoneLookup() {
Expand Down
66 changes: 33 additions & 33 deletions internal/components/src/components/cdn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,42 +161,42 @@ export class Cdn extends Component {
function lookupHostedZoneId() {
if (!domain) return;

return domain.apply(async (domain) => {
if (domain.hostedZoneId) return domain.hostedZoneId;
const domainName = domain.hostedZone ?? domain.domainName;
//return domain.apply(async (domain) => {
// if (domain.hostedZoneId) return domain.hostedZoneId;
// const domainName = domain.hostedZone ?? domain.domainName;

// Split domainName by "." and try to find the longest matching zone
// ie. for "my.app.domain.com"
// try "my.app.domain.com", "app.domain.com", "domain.com
const parts = domainName.split(".");
for (let i = 0; i <= parts.length - 2; i++) {
try {
const zone = await aws.route53.getZone({
name: parts.slice(i).join("."),
});
return zone.zoneId;
} catch (e) {
if (e.message.includes("no matching Route53Zone found")) {
continue;
}
throw e;
}
}
// // Split domainName by "." and try to find the longest matching zone
// // ie. for "my.app.domain.com"
// // try "my.app.domain.com", "app.domain.com", "domain.com
// const parts = domainName.split(".");
// for (let i = 0; i <= parts.length - 2; i++) {
// try {
// const zone = await aws.route53.getZone({
// name: parts.slice(i).join("."),
// });
// return zone.zoneId;
// } catch (e) {
// if (e.message.includes("no matching Route53Zone found")) {
// continue;
// }
// throw e;
// }
// }

throw new Error(`Could not find hosted zone for domain ${domain}`);
});
// throw new Error(`Could not find hosted zone for domain ${domain}`);
//});

// return domain.apply((domain) => {
// if (domain.hostedZoneId) return output(domain.hostedZoneId);
//
// return new HostedZoneLookup(
// `${name}HostedZoneLookup`,
// {
// domain: domain.hostedZone ?? domain.domainName,
// },
// { parent }
// ).zoneId;
// });
return domain.apply((domain) => {
if (domain.hostedZoneId) return output(domain.hostedZoneId);

return new HostedZoneLookup(
`${name}HostedZoneLookup`,
{
domain: domain.hostedZone ?? domain.domainName,
},
{ parent }
).zoneId;
});
}

function createSsl() {
Expand Down
16 changes: 6 additions & 10 deletions internal/components/src/components/providers/hosted-zone-lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,10 @@ interface Inputs {
domain: string;
}

interface Outputs {
zoneId: string;
}

class Provider implements dynamic.ResourceProvider {
async create(inputs: Inputs): Promise<dynamic.CreateResult> {
const zoneId = await this.lookup(inputs.domain);
const outs: Outputs = { zoneId };
return { id: zoneId, outs };
return { id: zoneId, outs: { zoneId } };
}

async update(
Expand All @@ -31,8 +26,7 @@ class Provider implements dynamic.ResourceProvider {
news: Inputs
): Promise<dynamic.UpdateResult> {
const zoneId = await this.lookup(news.domain);
const outs: Outputs = { zoneId };
return { outs };
return { outs: { zoneId } };
}

async lookup(domain: string) {
Expand Down Expand Up @@ -64,9 +58,11 @@ class Provider implements dynamic.ResourceProvider {
}
}

export class HostedZoneLookup extends dynamic.Resource {
public readonly zoneId!: Output<string>;
export interface HostedZoneLookup {
zoneId: Output<string>;
}

export class HostedZoneLookup extends dynamic.Resource {
constructor(
name: string,
args: HostedZoneLookupInputs,
Expand Down

0 comments on commit df6d35d

Please sign in to comment.