Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions code/builders/builder-vite/src/vite-server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Options } from 'storybook/internal/types';

import type { Server } from 'http';
import type { InlineConfig, ServerOptions } from 'vite';

import { getAssetsInclude } from './assetsInclude';
import { sanitizeEnvVars } from './envs';
import { getOptimizeDeps } from './optimizeDeps';
import { commonConfig } from './vite-config';
Expand All @@ -12,7 +12,7 @@ export async function createViteServer(options: Options, devServer: Server) {

const commonCfg = await commonConfig(options, 'development');

const config = {
const config: InlineConfig & { server: ServerOptions } = {
...commonCfg,
// Set up dev server
server: {
Expand All @@ -29,6 +29,12 @@ export async function createViteServer(options: Options, devServer: Server) {
optimizeDeps: await getOptimizeDeps(commonCfg, options),
};

const ipRegex = /^(?:\d{1,3}\.){3}\d{1,3}$|^(?:[a-fA-F0-9]{1,4}:){7}[a-fA-F0-9]{1,4}$/;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider extracting this regex to a constant at module level since it's a static pattern that could be reused


config.server.allowedHosts =
Comment thread
JSMike marked this conversation as resolved.
commonCfg.server?.allowedHosts ??
(options.host && !ipRegex.test(options.host) ? [options.host.toLowerCase()] : true);
Comment on lines +34 to +36

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider adding a comment explaining the logic: true allows all hosts, array restricts to specific hosts


const finalConfig = await presets.apply('viteFinal', config, options);

const { createServer } = await import('vite');
Expand Down
6 changes: 3 additions & 3 deletions code/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29790,8 +29790,8 @@ __metadata:
linkType: hard

"vite@npm:^4.0.0, vite@npm:^4.0.4":
version: 4.5.1
resolution: "vite@npm:4.5.1"
version: 4.5.9
resolution: "vite@npm:4.5.9"
dependencies:
esbuild: "npm:^0.18.10"
fsevents: "npm:~2.3.2"
Expand Down Expand Up @@ -29825,7 +29825,7 @@ __metadata:
optional: true
bin:
vite: bin/vite.js
checksum: 10c0/352a94b13f793e4bcbc424d680a32507343223eeda8917fde0f23c1fa1ba3db7c806dade8461ca5cfb270154ddb8895a219fdd4384519fe9b8e46d1cf491a890
checksum: 10c0/d51b9da32fddc6079333a16306c4c70d6ea6b253267931b5cd5d1c521bcfbee926297dc6878da79b0f1e058b7eef72555226be701fae376c2dfae9f83bc5699a
languageName: node
linkType: hard

Expand Down