Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/common/base64.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export const encodeBase64 = (str: string) => Buffer.from(str, 'utf-8').toString('base64');

export const encodeBase64ForRosId = (str: string) => encodeBase64(str).replace(/=+$/, '');
1 change: 1 addition & 0 deletions src/parser/bucketParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const parseBucket = (buckets: {
website: bucket.website
? {
code: bucket.website.code,
domain: bucket.website.domain,
index: bucket.website.index ?? 'index.html',
error_page: bucket.website.error_page ?? '404.html',
error_code: bucket.website.error_code ?? 404,
Expand Down
12 changes: 11 additions & 1 deletion src/stack/rosStack/bucket.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ActionContext, BucketAccessEnum, BucketDomain } from '../../types';
import * as oss from '@alicloud/ros-cdk-oss';
import * as ros from '@alicloud/ros-cdk-core';
import { getAssets, replaceReference } from '../../common';
import { encodeBase64ForRosId, getAssets, replaceReference } from '../../common';
import * as ossDeployment from '@alicloud/ros-cdk-ossdeployment';
import path from 'node:path';
import { RosRole } from '@alicloud/ros-cdk-ram';
Expand Down Expand Up @@ -86,5 +86,15 @@ export const resolveBuckets = (
true,
);
}
if (bucket.website?.domain) {
new oss.Domain(
scope,
`${bucket.key}_custom_domain_${encodeBase64ForRosId(bucket.website.domain)}`,
{
bucketName: ossBucket.attrName,
domainName: replaceReference(bucket.website.domain, context),
},
);
}
});
};
6 changes: 3 additions & 3 deletions src/stack/rosStack/event.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as ros from '@alicloud/ros-cdk-core';
import { ActionContext, EventDomain, EventTypes, ServerlessIac } from '../../types';
import * as ram from '@alicloud/ros-cdk-ram';
import { encodeBase64, replaceReference } from '../../common';
import { encodeBase64ForRosId, replaceReference } from '../../common';
import * as agw from '@alicloud/ros-cdk-apigateway';
import { isEmpty } from 'lodash';

Expand Down Expand Up @@ -81,9 +81,9 @@ export const resolveEvents = (

apiGateway.forEach((event) => {
event.triggers.forEach((trigger) => {
const key = encodeBase64(
const key = encodeBase64ForRosId(
replaceReference(`${trigger.method}_${trigger.path}`, context),
).replace(/=+$/, '');
);

const api = new agw.RosApi(
scope,
Expand Down
2 changes: 2 additions & 0 deletions src/types/domains/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type BucketRaw = {
};
website?: {
code: string;
domain?: string;
index?: string;
error_page?: string;
error_code?: number;
Expand Down Expand Up @@ -45,6 +46,7 @@ export type BucketDomain = {
};
website?: {
index: string;
domain?: string;
code: string;
error_page: string;
error_code: number;
Expand Down
3 changes: 3 additions & 0 deletions src/validator/bucketSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export const bucketSchema = {
code: {
type: 'string',
},
domain: {
type: 'string',
},
index: {
type: 'string',
},
Expand Down
10 changes: 10 additions & 0 deletions tests/fixtures/deployFixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,7 @@ export const bucketWithWebsiteIac = {
name: 'my-bucket',
website: {
code: 'tests/fixtures/artifacts/large-artifact.zip',
domain: 'my-bucket.com',
index: 'index.html',
error_page: '404.html',
error_code: 404,
Expand Down Expand Up @@ -1398,6 +1399,15 @@ export const bucketWithWebsiteRos = {
},
Type: 'ALIYUN::OSS::Bucket',
},
my_bucket_custom_domain_bXktYnVja2V0LmNvbQ: {
Properties: {
BucketName: {
'Fn::GetAtt': ['my_bucket', 'Name'],
},
DomainName: 'my-bucket.com',
},
Type: 'ALIYUN::OSS::Domain',
},
si_auto_my_bucket_bucket_code_deployment: {
Properties: {
Parameters: {
Expand Down
2 changes: 1 addition & 1 deletion tests/stack/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ describe('Unit tests for stack deployment', () => {
]);
});

it('should deploy bucket as a website when website field is provided', async () => {
it('should deploy bucket as a website when website field is provided', async () => {
const stackName = 'my-website-bucket-stack';
mockedRosStackDeploy.mockResolvedValue(stackName);

Expand Down