Skip to content

Commit

Permalink
Switch to named server config exports
Browse files Browse the repository at this point in the history
  • Loading branch information
jhildenbiddle committed Dec 21, 2023
1 parent 82fefbd commit 71234f9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 25 deletions.
4 changes: 2 additions & 2 deletions jest.config.js
@@ -1,6 +1,6 @@
import serverConfigs from './server.configs.js';
import { testConfig } from './server.configs.js';

const { hostname, port } = serverConfigs.test;
const { hostname, port } = testConfig;
const TEST_HOST = `http://${hostname}:${port}`;
const sharedConfig = {
errorOnDeprecated: true,
Expand Down
4 changes: 2 additions & 2 deletions playwright.config.js
@@ -1,7 +1,7 @@
import { devices } from '@playwright/test';
import serverConfigs from './server.configs.js';
import { testConfig } from './server.configs.js';

const { hostname, port } = serverConfigs.test;
const { hostname, port } = testConfig;
const TEST_HOST = `http://${hostname}:${port}`;

process.env.TEST_HOST = TEST_HOST;
Expand Down
20 changes: 7 additions & 13 deletions server.configs.js
Expand Up @@ -6,7 +6,7 @@ const __filename = url.fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

// Production (CDN URLs, watch disabled)
const prod = {
export const prodConfig = {
hostname: '127.0.0.1',
notify: false,
open: false,
Expand All @@ -19,13 +19,13 @@ const prod = {
};

// Development (local URLs, watch enabled)
const dev = {
...prod,
export const devConfig = {
...prodConfig,
files: ['CHANGELOG.md', 'docs/**/*', 'lib/**/*'],
port: 3000,
rewriteRules,
server: {
...prod.server,
...prodConfig.server,
routes: {
'/changelog.md': path.resolve(__dirname, 'CHANGELOG.md'),
'/lib': path.resolve(__dirname, 'lib'),
Expand All @@ -36,11 +36,11 @@ const dev = {
};

// Test (local URLs, watch disabled)
const test = {
...dev,
export const testConfig = {
...devConfig,
port: 4000,
server: {
...dev.server,
...devConfig.server,
middleware: [
// Blank page required for test environment
{
Expand All @@ -56,9 +56,3 @@ const test = {
snippet: false,
watch: false,
};

export default {
dev,
prod,
test,
};
10 changes: 4 additions & 6 deletions server.js
@@ -1,15 +1,13 @@
import { create } from 'browser-sync';
import serverConfigs from './server.configs.js';
import { devConfig, prodConfig } from './server.configs.js';

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

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

bsServer.init(settings);
bsServer.init(config);
4 changes: 2 additions & 2 deletions test/config/server.js
@@ -1,13 +1,13 @@
import * as process from 'node:process';
import { create } from 'browser-sync';
import serverConfigs from '../../server.configs.js';
import { testConfig } from '../../server.configs.js';

const bsServer = create();

export async function startServer() {
// Wait for server to start
return new Promise(resolve => {
const settings = serverConfigs.test;
const settings = testConfig;

console.log('\n');

Expand Down

0 comments on commit 71234f9

Please sign in to comment.