diff --git a/packages/amplify-appsync-simulator/package.json b/packages/amplify-appsync-simulator/package.json index 86f1ed1a5da..6a77bcaf69e 100644 --- a/packages/amplify-appsync-simulator/package.json +++ b/packages/amplify-appsync-simulator/package.json @@ -44,7 +44,6 @@ "graphql": "^15.5.0", "graphql-iso-date": "^3.6.1", "graphql-subscriptions": "^1.1.0", - "ip": "^1.1.9", "js-string-escape": "^1.0.1", "jwt-decode": "^2.2.0", "libphonenumber-js": "1.9.47", diff --git a/packages/amplify-appsync-simulator/src/server/index.ts b/packages/amplify-appsync-simulator/src/server/index.ts index d533d61b7ee..24e493f5898 100644 --- a/packages/amplify-appsync-simulator/src/server/index.ts +++ b/packages/amplify-appsync-simulator/src/server/index.ts @@ -5,14 +5,25 @@ import { Server, createServer } from 'http'; import { createServer as createHttpsServer } from 'https'; import { readFileSync } from 'fs'; import { fromEvent } from 'promise-toolbox'; -import { address as getLocalIpAddress } from 'ip'; import { AppSyncSimulatorSubscriptionServer } from './websocket-subscription'; import getPort from 'get-port'; import { REALTIME_SUBSCRIPTION_PATH } from './subscription/websocket-server/server'; +import os from 'os'; const BASE_PORT = 8900; const MAX_PORT = 9999; +function getLocalIpAddress(): string { + const interfaces = os.networkInterfaces(); + const internalAddresses = Object.keys(interfaces) + .map((nic) => { + const addresses = interfaces[nic].filter((details) => details.internal); + return addresses.length ? addresses[0].address : undefined; + }) + .filter(Boolean); + return internalAddresses.length ? internalAddresses[0] : '127.0.0.1'; +} + export class AppSyncSimulatorServer { private _operationServer: OperationServer; private _httpServer: Server; diff --git a/yarn.lock b/yarn.lock index cd3b7e2241c..44fb4b7a577 100644 --- a/yarn.lock +++ b/yarn.lock @@ -123,7 +123,6 @@ __metadata: graphql: ^15.5.0 graphql-iso-date: ^3.6.1 graphql-subscriptions: ^1.1.0 - ip: ^1.1.9 jose: ^5.2.0 js-string-escape: ^1.0.1 jwt-decode: ^2.2.0 @@ -21603,7 +21602,7 @@ __metadata: languageName: node linkType: hard -"ip@npm:^1.1.8, ip@npm:^1.1.9": +"ip@npm:^1.1.8": version: 1.1.9 resolution: "ip@npm:1.1.9" checksum: 5af58bfe2110c9978acfd77a2ffcdf9d33a6ce1c72f49edbaf16958f7a8eb979b5163e43bb18938caf3aaa55cdacde4e470874c58ca3b4b112ea7a30461a0c27