Skip to content

Commit

Permalink
implement usage of aws_endpoint_url
Browse files Browse the repository at this point in the history
  • Loading branch information
pinzon committed Jan 29, 2024
1 parent 04f71f8 commit 32f232f
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ const TYPESCRIPT_PLUGIN_BUILD_DIR_ESBUILD = '.esbuild/.build'; //TODO detect fro
// Default edge port to use with host
const DEFAULT_EDGE_PORT = '4566';

Check failure on line 25 in src/index.js

View workflow job for this annotation

GitHub Actions / Serverless LocalStack CI (2)

'DEFAULT_EDGE_PORT' is assigned a value but never used

// Default AWS endpoint URL
const DEFAULT_AWS_ENDPOINT_URL = "https://localhost.localstack.cloud:4566";

// Cache hostname to avoid unnecessary connection checks
var resolvedHostname = undefined;

const awsEndpointUrl = process.env.AWS_ENDPOINT_URL || DEFAULT_AWS_ENDPOINT_URL;

class LocalstackPlugin {
constructor(serverless, options) {

Expand Down Expand Up @@ -700,8 +705,23 @@ class LocalstackPlugin {

/* Utility functions below */

getEndpointPort(){
const url = new URL(awsEndpointUrl);
return url.port;
}

getEndpointHostname(){
const url = new URL(awsEndpointUrl);
return url.hostname;
}

getEndpointProtocol(){
const url = new URL(awsEndpointUrl);
return url.protocol;
}

getEdgePort() {
return process.env.EDGE_PORT || this.config.edgePort || DEFAULT_EDGE_PORT;
return process.env.EDGE_PORT || this.config.edgePort || this.getEndpointPort();
}

/**
Expand All @@ -713,7 +733,7 @@ class LocalstackPlugin {
return resolvedHostname;
}

var hostname = process.env.LOCALSTACK_HOSTNAME || 'localhost';
var hostname = process.env.LOCALSTACK_HOSTNAME || this.getEndpointHostname();
if (this.config.host) {
hostname = this.config.host;
if (hostname.indexOf("://") !== -1) {
Expand Down Expand Up @@ -782,7 +802,11 @@ class LocalstackPlugin {
return this.injectHostnameIntoLocalhostURL(process.env.AWS_ENDPOINT_URL, hostname);
}
hostname = hostname || 'localhost';
const proto = TRUE_VALUES.includes(process.env.USE_SSL) ? 'https' : 'http';

let proto = this.getEndpointProtocol();
if (process.env.USE_SSL) {
proto = TRUE_VALUES.includes(process.env.USE_SSL) ? 'https' : 'http';
}
const port = this.getEdgePort();
// little hack here - required to remove the default HTTPS port 443, as otherwise
// routing for some platforms and ephemeral instances (e.g., on namespace.so) fails
Expand Down

0 comments on commit 32f232f

Please sign in to comment.