From ffbb5d7e75a040c5f3db5f708364d0f09a041983 Mon Sep 17 00:00:00 2001 From: Vitaly Date: Wed, 17 Jan 2024 08:07:20 +0530 Subject: [PATCH] display url to open local + network in dev! --- package.json | 3 +++ pnpm-lock.yaml | 13 +++++++++++++ server.js | 19 ++++++++++++++++++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index cb602816..642dd0de 100644 --- a/package.json +++ b/package.json @@ -117,6 +117,9 @@ "vitest": "^0.34.6", "yaml": "^2.3.2" }, + "optionalDependencies": { + "systeminformation": "^5.21.22" + }, "pnpm": { "overrides": { "three": "0.128.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 64b25b36..14a513ff 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -144,6 +144,10 @@ importers: workbox-build: specifier: ^7.0.0 version: 7.0.0 + optionalDependencies: + systeminformation: + specifier: ^5.21.22 + version: 5.21.22 devDependencies: '@storybook/addon-essentials': specifier: ^7.4.6 @@ -13417,6 +13421,15 @@ packages: resolution: {integrity: sha512-AsS729u2RHUfEra9xJrE39peJcc2stq2+poBXX8bcM08Y6g9j/i/PUzwNQqkaJde7Ntg1TO7bSREbR5sdosQ+g==} dev: true + /systeminformation@5.21.22: + resolution: {integrity: sha512-gNHloAJSyS+sKWkwvmvozZ1eHrdVTEsynWMTY6lvLGBB70gflkBQFw8drXXr1oEXY84+Vr9tOOrN8xHZLJSycA==} + engines: {node: '>=8.0.0'} + os: [darwin, linux, win32, freebsd, openbsd, netbsd, sunos, android] + hasBin: true + requiresBuild: true + dev: false + optional: true + /tabbable@6.2.0: resolution: {integrity: sha512-Cat63mxsVJlzYvN51JmVXIgNoUokrIaT2zLclCXjRd8boZ0004U4KCs/sToJ75C6sdlByWxpYnb5Boif1VSFew==} dev: false diff --git a/server.js b/server.js index b6dd4135..f8caf3a6 100644 --- a/server.js +++ b/server.js @@ -7,6 +7,10 @@ const path = require('path') const cors = require('cors') const https = require('https') const fs = require('fs') +let siModule +try { + siModule = require('systeminformation') +} catch (err) { } // Create our app const app = express() @@ -44,8 +48,21 @@ const port = (require.main === module ? process.argv[2] : portArg !== -1 ? proce // Start the server const server = isProd ? undefined : - app.listen(port, function () { + app.listen(port, async function () { console.log('Server listening on port ' + server.address().port) + if (siModule) { + const _interfaces = await siModule.networkInterfaces() + const interfaces = Array.isArray(_interfaces) ? _interfaces : [_interfaces] + let netInterface = interfaces.find(int => int.default) + if (!netInterface) { + netInterface = interfaces.find(int => !int.virtual) ?? interfaces[0] + console.warn('Failed to get the default network interface, searching for fallback') + } + if (netInterface) { + const address = netInterface.ip4 + console.log(`You can access the server on http://localhost:8080 or http://${address}:${port}`) + } + } }) module.exports = { app }