0

` webpack.dev.js

const path = require('path')
const HtmlWebPackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const webpack = require('webpack');
const setupProxy = require('./src/setupProxy.js');
const proxy = require('http-proxy-middleware');

module.exports = {
    mode:"development",
    entry: "./src/index.js",
    output: {
        filename: "bundle.js",
        path: path.resolve(__dirname, 'dist'),
        clean: true,
        assetModuleFilename: 'images/[hash][ext][query]',
        publicPath:'/'
        
    },
    plugins: [
        new HtmlWebPackPlugin({
            template: './public/index.html'
        }),
        new MiniCssExtractPlugin(),
        new webpack.HotModuleReplacementPlugin()
     
    ],
    module: {
        rules: [
            {
                test: /\.(js|jsx)$/,
                exclude: /node_modules/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ['@babel/preset-react', '@babel/preset-env']
                    }
                }
            },
            {
              test: /\.scss$/,
              use: [
                'style-loader',
                'css-loader',
                'sass-loader',
              ],
            },
            {
              test: /\.css$/,
              use: [
                'style-loader',
                'css-loader',
              ],
            },
            {
                test:/\.(png|jpg|gif)$/,
                type:"asset/resource"
            },
            {
              test: /\.(woff(2)?|eot|ttf|otf|svg|)$/,
              type: 'asset/inline',
              
            },

        ]
    },
    devServer: {
        static: {
            directory: path.join(__dirname, 'dist')
        },
        onBeforeSetupMiddleware: function(app) {
          setupProxy(app);
        },
        // historyApiFallback: true,
        hot: true,
        // inline: true,
      
        // host: 'localhost', // Defaults to `localhost`
        port: 3002,
        open:true,
        // proxy: {
        //   '/': {
        //     target: 'http://localhost:3080/',
        //     // secure: false,
        //     changeOrigin: true
        //   }
        // },
        proxy: {
          "*": "http://[::1]:3080",
          "secure": false,
          "changeOrigin": true
        },
        // proxy: {
        //   '/api': 'http://localhost:3080',
        // },
        
        // proxy:{

        //         '*':"http://localhost:3002/"
          
        //       },
          
          // proxy: {
          //   // '/': {
          //   //   target: 'http://localhost:3080/',
          //   //   // pathRewrite: {'^/': ''},
          //   //   changeOrigin: true,
          //   // },
          //   onAfterSetupMiddleware: function(devServer) {
          //     devServer.app.use(
          //       '/',
          //       proxy({
          //         target: 'http://localhost:3080/',
          //         // pathRewrite: {'^/api': ''},
          //         changeOrigin: true,
          //       })
          //     );
          //   },
          // },
          
       
    }

}

and scripts are

"dev": "webpack serve --config webpack.dev.js",
"start": "npm run dev ",

everything is working fine only Api's are failing. How to fix endpoints getting success

`

tried proxying and updated express configurations but no luck. Tried below one as well Running a node express server using webpack-dev-server .. no luck

quick help much appreciated

syeda
  • 1

0 Answers0