Skip to content

Commit 8e1adec

Browse files
jhildenbiddlesy-records
authored andcommitted
Switch to named server config exports
1 parent 47656e1 commit 8e1adec

File tree

5 files changed

+17
-25
lines changed

5 files changed

+17
-25
lines changed

jest.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import serverConfigs from './server.configs.js';
1+
import { testConfig } from './server.configs.js';
22

3-
const { hostname, port } = serverConfigs.test;
3+
const { hostname, port } = testConfig;
44
const TEST_HOST = `http://${hostname}:${port}`;
55
const sharedConfig = {
66
errorOnDeprecated: true,

playwright.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { devices } from '@playwright/test';
2-
import serverConfigs from './server.configs.js';
2+
import { testConfig } from './server.configs.js';
33

4-
const { hostname, port } = serverConfigs.test;
4+
const { hostname, port } = testConfig;
55
const TEST_HOST = `http://${hostname}:${port}`;
66

77
process.env.TEST_HOST = TEST_HOST;

server.configs.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const __filename = url.fileURLToPath(import.meta.url);
66
const __dirname = path.dirname(__filename);
77

88
// Production (CDN URLs, watch disabled)
9-
const prod = {
9+
export const prodConfig = {
1010
hostname: '127.0.0.1',
1111
notify: false,
1212
open: false,
@@ -19,13 +19,13 @@ const prod = {
1919
};
2020

2121
// Development (local URLs, watch enabled)
22-
const dev = {
23-
...prod,
22+
export const devConfig = {
23+
...prodConfig,
2424
files: ['CHANGELOG.md', 'docs/**/*', 'lib/**/*'],
2525
port: 3000,
2626
rewriteRules,
2727
server: {
28-
...prod.server,
28+
...prodConfig.server,
2929
routes: {
3030
'/changelog.md': path.resolve(__dirname, 'CHANGELOG.md'),
3131
'/lib': path.resolve(__dirname, 'lib'),
@@ -36,11 +36,11 @@ const dev = {
3636
};
3737

3838
// Test (local URLs, watch disabled)
39-
const test = {
40-
...dev,
39+
export const testConfig = {
40+
...devConfig,
4141
port: 4000,
4242
server: {
43-
...dev.server,
43+
...devConfig.server,
4444
middleware: [
4545
// Blank page required for test environment
4646
{
@@ -56,9 +56,3 @@ const test = {
5656
snippet: false,
5757
watch: false,
5858
};
59-
60-
export default {
61-
dev,
62-
prod,
63-
test,
64-
};

server.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import { create } from 'browser-sync';
2-
import serverConfigs from './server.configs.js';
2+
import { devConfig, prodConfig } from './server.configs.js';
33

44
const bsServer = create();
55
const args = process.argv.slice(2);
6-
const configName =
7-
Object.keys(serverConfigs).find(name => args.includes(`--${name}`)) || 'prod';
8-
const settings = serverConfigs[configName];
9-
const isWatch = Boolean(settings.files) && settings.watch !== false;
6+
const config = args.includes('--dev') ? devConfig : prodConfig;
7+
const isWatch = Boolean(config.files) && config.watch !== false;
108
const urlType = configName === 'prod' ? 'CDN' : 'local';
119

1210
// prettier-ignore
1311
console.log(`\nStarting ${configName} server (${urlType} URLs, watch: ${isWatch})\n`);
1412

15-
bsServer.init(settings);
13+
bsServer.init(config);

test/config/server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import * as process from 'node:process';
22
import { create } from 'browser-sync';
3-
import serverConfigs from '../../server.configs.js';
3+
import { testConfig } from '../../server.configs.js';
44

55
const bsServer = create();
66

77
export async function startServer() {
88
// Wait for server to start
99
return new Promise(resolve => {
10-
const settings = serverConfigs.test;
10+
const settings = testConfig;
1111

1212
console.log('\n');
1313

0 commit comments

Comments
 (0)