Skip to content

Commit 0c1f785

Browse files
authored
Merge pull request #888 from OneSignal/improvement/no-port-flag
Improvement/no port flag
2 parents 72e236c + 9e16627 commit 0c1f785

File tree

11 files changed

+32
-10
lines changed

11 files changed

+32
-10
lines changed

build/config/page-sdk-es6.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const apiOrigin = process.env.API_ORIGIN || "onesignal.com"
1212
const isProdBuild = process.env.ENV === "production";
1313
const nodeEnv = isProdBuild ? "production" : "development";
1414
const isHttps = process.env.HTTPS;
15+
const noDevPort = process.env.NO_DEV_PORT;
1516
const tests = process.env.TESTS;
1617
const sdkVersion = process.env.npm_package_config_sdkVersion;
1718

@@ -26,6 +27,7 @@ async function getWebpackPlugins() {
2627
__API_TYPE__: JSON.stringify(apiEnv),
2728
__API_ORIGIN__: JSON.stringify(apiOrigin),
2829
__IS_HTTPS__: isHttps === "true",
30+
__NO_DEV_PORT__: noDevPort === "true",
2931
__TEST__: !!tests,
3032
__VERSION__: sdkVersion,
3133
__LOGGING__: env === "development",

build/config/sdk.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const apiOrigin = process.env.API_ORIGIN || "localhost";
1515
const isProdBuild = process.env.ENV === "production";
1616
const nodeEnv = isProdBuild ? "production" : "development";
1717
const isHttps = process.env.HTTPS;
18+
const noDevPort = process.env.NO_DEV_PORT;
1819
const tests = process.env.TESTS;
1920
const sdkVersion = process.env.npm_package_config_sdkVersion;
2021

@@ -63,6 +64,7 @@ async function getWebpackPlugins() {
6364
__API_TYPE__: JSON.stringify(apiEnv),
6465
__API_ORIGIN__: JSON.stringify(apiOrigin),
6566
__IS_HTTPS__: isHttps === "true",
67+
__NO_DEV_PORT__: noDevPort === "true",
6668
__TEST__: !!tests,
6769
__VERSION__: sdkVersion,
6870
__LOGGING__: env === "development",

build/config/serviceworker.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const apiOrigin = process.env.API_ORIGIN || "localhost";
1111
const isProdBuild = process.env.ENV === "production";
1212
const nodeEnv = isProdBuild ? "production" : "development";
1313
const isHttps = process.env.HTTPS;
14+
const noDevPort = process.env.NO_DEV_PORT;
1415
const tests = process.env.TESTS;
1516
const sdkVersion = process.env.npm_package_config_sdkVersion;
1617

@@ -24,6 +25,7 @@ async function getWebpackPlugins() {
2425
__API_TYPE__: JSON.stringify(apiEnv),
2526
__API_ORIGIN__: JSON.stringify(apiOrigin),
2627
__IS_HTTPS__: isHttps === "true",
28+
__NO_DEV_PORT__: noDevPort === "true",
2729
__TEST__: !!tests,
2830
__VERSION__: sdkVersion,
2931
__LOGGING__: env === "development",

build/config/webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ async function getBuildDefines() {
202202
__API_TYPE__: process.env.API,
203203
__API_ORIGIN__: process.env.API_ORIGIN,
204204
__IS_HTTPS__: process.env.HTTPS,
205+
__NO_DEV_PORT__: process.env.NO_DEV_PORT,
205206
__TEST__: !!process.env.TESTS,
206207
__VERSION__: process.env.npm_package_config_sdkVersion,
207208
__LOGGING__: process.env.ENV === "development",

build/scripts/build.sh

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ case $key in
3131
HTTPS=false
3232
shift # past argument
3333
;;
34+
--no-port)
35+
NO_DEV_PORT=true
36+
shift # past argument
37+
;;
3438
*) # unknown option
3539
POSITIONAL+=("$1") # save it in an array for later
3640
shift # past argument
@@ -43,6 +47,8 @@ API_ORIGIN=${API_ORIGIN:-"onesignal.com"}
4347
ENV=${ENV:-"development"}
4448
API=${API:-"production"}
4549
HTTPS=${HTTPS:-true}
50+
NO_DEV_PORT=${NO_DEV_PORT:-false}
51+
4652

4753
if [ "$ENV" = "staging" ]; then
4854
API="staging"
@@ -55,12 +61,15 @@ echo "API_ORIGIN = ${API_ORIGIN}"
5561
echo "HTTPS = ${HTTPS}"
5662
echo "ENV = ${ENV}"
5763
echo "API = ${API}"
64+
echo "NO_DEV_PORT = ${NO_DEV_PORT}"
5865
echo "Unknown options -> ${POSITIONAL}"
5966
set -- "${POSITIONAL[@]}" # restore positional parameters
6067

68+
# build local SW file for dev env
69+
./build/scripts/buildServiceWorker.sh $BUILD_ORIGIN
6170

62-
ENV=$ENV API=$API BUILD_ORIGIN=$BUILD_ORIGIN API_ORIGIN=$API_ORIGIN HTTPS=$HTTPS yarn transpile:sources
63-
ENV=$ENV API=$API BUILD_ORIGIN=$BUILD_ORIGIN API_ORIGIN=$API_ORIGIN HTTPS=$HTTPS yarn bundle-sw
64-
ENV=$ENV API=$API BUILD_ORIGIN=$BUILD_ORIGIN API_ORIGIN=$API_ORIGIN HTTPS=$HTTPS yarn bundle-sdk
65-
ENV=$ENV API=$API BUILD_ORIGIN=$BUILD_ORIGIN API_ORIGIN=$API_ORIGIN HTTPS=$HTTPS yarn bundle-page-sdk-es6
66-
ENV=$ENV API=$API BUILD_ORIGIN=$BUILD_ORIGIN API_ORIGIN=$API_ORIGIN HTTPS=$HTTPS ./build/scripts/publish.sh
71+
ENV=$ENV API=$API BUILD_ORIGIN=$BUILD_ORIGIN API_ORIGIN=$API_ORIGIN HTTPS=$HTTPS NO_DEV_PORT=$NO_DEV_PORT yarn transpile:sources
72+
ENV=$ENV API=$API BUILD_ORIGIN=$BUILD_ORIGIN API_ORIGIN=$API_ORIGIN HTTPS=$HTTPS NO_DEV_PORT=$NO_DEV_PORT yarn bundle-sw
73+
ENV=$ENV API=$API BUILD_ORIGIN=$BUILD_ORIGIN API_ORIGIN=$API_ORIGIN HTTPS=$HTTPS NO_DEV_PORT=$NO_DEV_PORT yarn bundle-sdk
74+
ENV=$ENV API=$API BUILD_ORIGIN=$BUILD_ORIGIN API_ORIGIN=$API_ORIGIN HTTPS=$HTTPS NO_DEV_PORT=$NO_DEV_PORT yarn bundle-page-sdk-es6
75+
ENV=$ENV API=$API BUILD_ORIGIN=$BUILD_ORIGIN API_ORIGIN=$API_ORIGIN HTTPS=$HTTPS NO_DEV_PORT=$NO_DEV_PORT ./build/scripts/publish.sh
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
# Builds the local service worker file for express_webpack for use in local dev env
4+
echo "importScripts(\"https://${1}/sdks/Dev-OneSignalSDKWorker.js\");" > express_webpack/push/onesignal/OneSignalSDKWorker.js

express_webpack/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
## WebSDK Sandbox Environment
33
### Run Instructions
44
1. `docker-compose up`
5-
- If SSL certs need to be created, this will be done for you automatically with the common name default setting `texas` and alternative DNS names (this can be customized in `certs/gen-cert.sh`):
6-
- localhost
5+
- If SSL certs need to be created, this will be done for you automatically with the common name default setting `localhost` and alternative DNS names (this can be customized in `certs/gen-cert.sh`):
6+
- texas
77
- california
88
- oregon
99
- washington
@@ -75,6 +75,8 @@ All builds default to `https` unless `--http` is passed to the end of the build
7575
- HTTP: `4000`
7676
- HTTPS: `4001`
7777
78+
Use the **`--no-port`** build flag to build without a port number. This is useful when using a reverse proxy like [ngrok](https://ngrok.com/) to serve your localhost environment on the web.
79+
7880
**API**: dev-environment API calls will be made to the `3001` port (e.g: `<custom-origin>:3001`)
7981
8082
### Running in Combination with OneSignal Container (dev-dev)

express_webpack/push/onesignal/OneSignalSDKUpdaterWorker.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/managers/SdkEnvironment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ export default class SdkEnvironment {
289289

290290
switch (buildEnv) {
291291
case EnvironmentKind.Development:
292-
origin = `${protocol}://${buildOrigin}:${port}`;
292+
origin = __NO_DEV_PORT__ ? `${protocol}://${buildOrigin}` : `${protocol}://${buildOrigin}:${port}`;
293293
break;
294294
case EnvironmentKind.Staging:
295295
origin = `https://${buildOrigin}`;

src/utils/OneSignalShimLoader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class OneSignalShimLoader {
3333

3434
switch(__BUILD_TYPE__){
3535
case "development":
36-
return `${protocol}://${buildOrigin}:${port}/sdks/Dev-`;
36+
return __NO_DEV_PORT__ ? `${protocol}://${buildOrigin}/sdks/Dev-` : `${protocol}://${buildOrigin}:${port}/sdks/Dev-`;
3737
case "staging":
3838
return `https://${buildOrigin}/sdks/Staging-`;
3939
default:

0 commit comments

Comments
 (0)