Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lambda-tiler): always include access-control-allow-origin #2385

Merged
merged 4 commits into from
Jul 28, 2022
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
6 changes: 0 additions & 6 deletions packages/_infra/src/serve/lambda.tiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@ export class LambdaTiler extends Construct {
this.functionUrl = new lambda.FunctionUrl(this, 'LambdaCogUrl', {
function: this.lambdaNoVpc,
authType: lambda.FunctionUrlAuthType.NONE,
cors: {
allowedOrigins: ['*'],
allowedMethods: [lambda.HttpMethod.GET],
allowCredentials: false,
maxAge: cdk.Duration.minutes(1),
},
});

if (props.staticBucketName) {
Expand Down
10 changes: 4 additions & 6 deletions packages/lambda-tiler/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LogConfig } from '@basemaps/shared';
import { LambdaHttpResponse, LambdaUrlRequest, lf } from '@linzjs/lambda';
import { LambdaHttpResponse, lf } from '@linzjs/lambda';
import { tileAttributionGet } from './routes/attribution.js';
import { fontGet, fontList } from './routes/fonts.js';
import { healthGet } from './routes/health.js';
Expand Down Expand Up @@ -40,13 +40,11 @@ handler.router.hook('response', (req, res) => {
cacheB: CoSources.cache.cacheB.size,
});

// FunctionURLs automatically inject CORS responses for us
if (!(req instanceof LambdaUrlRequest) && req.headers.has('origin')) {
res.header('access-control-allow-origin', '*');
}
// Force access-control-allow-origin to everything
res.header('access-control-allow-origin', '*');
});

// CORS is handled by function url hook so just return ok if the route exists
// CORS is handled by response hook so just return ok if the route exists
handler.router.options('*', (req) => {
const route = handler.router.router.find('GET', req.path);
if (route == null) return NotFound();
Expand Down
3 changes: 2 additions & 1 deletion packages/lambda-tiler/src/util/source.cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,5 @@ export class SourceCache {
}
}

export const CoSources = new SourceCache(256 * 1024 * 1024);
/** Approx 1GB */
export const CoSources = new SourceCache(1000 * 1000 * 1000);