Skip to content

Commit

Permalink
Use a utility function to get IP for Playwright server
Browse files Browse the repository at this point in the history
Use --host
  • Loading branch information
tyom committed Jan 5, 2024
1 parent e36f010 commit 4ebcbc0
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions playwright.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
import { defineConfig } from '@playwright/test';
import { networkInterfaces } from 'os';

function getIPAddress() {
const interfaces = networkInterfaces();
for (const name in interfaces) {
const iface = interfaces[name];

for (const alias of iface) {
if (
alias.family === 'IPv4' &&
alias.address !== '127.0.0.1' &&
!alias.internal
) {
return alias.address;
}
}
}
return '0.0.0.0';
}

const PORT = process.env.PORT || 5173;
const serverUrl = `http://localhost:${PORT}`;
const serverUrl = `http://${getIPAddress()}:${PORT}`;

console.log('Server URL:', serverUrl);

export default defineConfig({
webServer: {
command: 'pnpm run dev',
command: 'pnpm run dev --host',
url: serverUrl,
reuseExistingServer: !process.env.CI,
},
Expand Down

0 comments on commit 4ebcbc0

Please sign in to comment.