Skip to content

Commit

Permalink
Custom proxy configuration for local development.
Browse files Browse the repository at this point in the history
  • Loading branch information
robol committed Nov 22, 2023
1 parent 7389ecc commit d7e8565
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions scripts/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@ const fs = require('fs');
const chalk = require('react-dev-utils/chalk');
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const clearConsole = require('react-dev-utils/clearConsole');
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
const {
choosePort,
createCompiler,
prepareProxy,
prepareUrls,
} = require('react-dev-utils/WebpackDevServerUtils');
const openBrowser = require('react-dev-utils/openBrowser');
const semver = require('semver');
const paths = require('../config/paths');
const configFactory = require('../config/webpack.config');
Expand Down Expand Up @@ -90,6 +87,7 @@ checkBrowsers(paths.appPath, isInteractive)
port,
paths.publicUrlOrPath.slice(0, -1)
);

// Create a webpack compiler that is configured with custom messages.
const compiler = createCompiler({
appName,
Expand All @@ -99,36 +97,34 @@ checkBrowsers(paths.appPath, isInteractive)
useTypeScript,
webpack,
});
// Load proxy config
const proxySetting = require(paths.appPackageJson).proxy;
const proxyConfig = prepareProxy(
proxySetting,
paths.appPublic,
paths.publicUrlOrPath
);

// Prepare proxy configuration
const proxyConfig = {
'/api/': {
target: process.env.SERVER_URL,
changeOrigin: true
},
'/config': {
target: process.env.SERVER_URL,
changeOrigin: true
},
'/login': {
target: process.env.SERVER_URL,
changeOrigin: true
}
}

// Serve webpack assets generated by the compiler over a web server.
const serverConfig = {
...createDevServerConfig(proxyConfig, urls.lanUrlForConfig),
host: HOST,
port,
};

const devServer = new WebpackDevServer(serverConfig, compiler);
// Launch WebpackDevServer.
devServer.startCallback(() => {
if (isInteractive) {
clearConsole();
}

if (env.raw.FAST_REFRESH && semver.lt(react.version, '16.10.0')) {
console.log(
chalk.yellow(
`Fast Refresh requires React 16.10 or higher. You are using React ${react.version}.`
)
);
}

console.log(chalk.cyan('Starting the development server...\n'));
openBrowser(urls.localUrlForBrowser);
});

['SIGINT', 'SIGTERM'].forEach(function (sig) {
Expand Down

0 comments on commit d7e8565

Please sign in to comment.