Configuring Proxy Settings for WebpackDevServer

I need assistance setting up a proxy using WebpackDevServer in my React/Node chrome extension. Currently, my server is running on localhost:4000, and the React frontend is on localhost:5000.

When trying to access the route /api/user/ticket using Axios, I am encountering an issue. The request is not being proxied through localhost:4000, but instead hitting the route of my chrome extension:

chrome-extension://fjkfhdsjkwerjhdksfhdjkshfds/api/ticket/user/
.

If I explicitly call localhost:4000/api/user/ticket, everything works properly. As I am new to webpack, I am unsure of what mistake I might be making. Any assistance would be highly appreciated. Thank you!

The webserver proxy has been implemented based on the information provided in the documentation

var server = new WebpackDevServer(
  {
    https: false,
    hot: false,
    client: false,
    proxy: {
      '/api': 'http://localhost:4000',
    },
    host: 'localhost',
    port: env.PORT,
    static: {
      directory: path.join(__dirname, '../build'),
    },
    devMiddleware: {
      publicPath: `http://localhost:${env.PORT}/`,
      writeToDisk: true,
    },
    headers: {
      'Access-Control-Allow-Origin': '*',
    },
    //urgent modification needed to prevent DNS attacks
    allowedHosts: 'all',
  },
  compiler
);

Answer №1

Despite unsuccessful attempts with the proxy, I managed to overcome this obstacle by implementing baseUrls in axios. By modifying them at a single location when switching between production and development environments, I could ensure its functionality. Although not perfect, it proved effective enough to complete the task at hand.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Enhance your web application with Material UI's powerful dat

Hey there, I've got a couple of questions about the Material UI - datagrid filter with type:dateTime. Is there a way to change the local format when selecting the date in the filter? It currently displays the AM/PM date format and I can't seem t ...

Retrieve information stored in a component's data variable

After creating a Vue repository using vue init webpack my-app My main.js file looks like this -- // The Vue build version to load with the import command // (runtime-only or standalone) has been set in webpack.base.conf with an alias. import Vue fro ...

Verification of the token using passport-azure-ad Strategy.prototype.jwtVerify has failed

I recently developed a web API by following this informative article: Developing Node.js WebAPI with Azure Active Directory const restify = require('restify'), restifyPlugins = require('restify-plugins'), config = require(&apo ...

What is the best way to transfer static assets from an npm package to a nuxt project?

Has anyone successfully sent assets from an npm package to a nuxt application before? I have a vue component within an npm package with the following structure: -src/ -assets/ -noun-filter.svg In this npm package, the vector image is included in the v ...

The assets folder is experiencing difficulties loading files on sub pages

I am organizing my files in a folder structure as shown below: assets bootstrap css style.css js jquery.min.js views partials head.ejs header.ejs scripts.ejs home.ejs user_registration.ejs Within my app.js file, the assets folder is set ...

What is the underlying mechanism behind the functionality of this straightforward node.js proxy?

I am running a frontend-only web application on Netlify that needs to interact with an API on OpenSubtitles.org. Despite the fact that OpenSubtitles.org supports CORS, I sometimes encounter preflight errors, leading me to implement a proxy solution. After ...

Steps to avoid IE11 prompt (Do you really want to leave this site)

In the midst of making a webpage, I find myself faced with the peculiar issue of only having a dropdown to select. To make matters worse, when attempting to navigate to the next page in IE11, a pesky message pops up. Curious about the default behavior of ...

What are the steps to set up a MEVN project to run on an intranet using nginx?

As a newcomer to the world of Vue, Node, Express, and MongoDB API while using Nginx, I have a question about where to place the port configuration. Can anyone provide insight on this? My project consists of a "client" folder and a "server" folder, both co ...

Mastering the use of getText() in Protractor with Page Object Model in Javascript

Having trouble retrieving specific values from my page object. The getText() method is returning the entire object instead of just the text, likely due to it being a Promise. I can provide my code if necessary, but I'm aiming to achieve something sim ...

What is preventing me from importing files from a directory labeled 'individuals'?

Currently, I am working on a MEAN app and encountered some issues with my Angular folder structure. Here are the errors I am facing: https://i.stack.imgur.com/UAliy.png Interestingly, when I changed the name of the 'users' folder to something el ...

Intermittently play a series of sound files, with only the final sound ringing out

My goal is to create an app that plays a sound based on a number input. I have several short MP3 audio files for different numbers, and I want the app to play these sounds in sequence. However, when I try to do this, only the last sound corresponding to th ...

Display a dynamic variable within React's HTML code

const fetchTime = () => { const currentDate = new Date(); const currentTime = currentDate + ' ' + currentDate.getHours() + ":" + currentDate.getMinutes() + ":" + currentDate.getSeconds(); return {currentTime}; } export default fun ...

Position the buttons in the react children's application

**Looking for help on positioning Black Widow in the center-left and Hulk at the bottom left of the screen. I'm having trouble figuring it out, does anyone have any tips? Also, I only want to isolate the buttons to each picture. Not sure if I need to ...

javascript implement a process to iteratively submit a form using ajax

I have a dynamic form with an unknown number of input fields that are not fixed. While searching for solutions, I came across jQuery ajax form submission which requires manually constructing the query string. In this scenario, the number of input fields ...

The command 'npm-run-all' is not valid and cannot be found, please check the command and try again

#Issue : Error running npm run dist for Bootstrap #Error Detail: 'npm-run-all' is not recognized as a valid command, program or batch file. Recently installed Node.js and chocolatey. Verified everything added to the system path. Attempting to ex ...

Unending Mongoose request delay

Situation: Using Mongoose v4.7.6 Working with MongoDB v3.2.11 Currently facing issues regarding database errors in my software. Encountering a problem where mongoose requests hang when the database is disconnected and only resume once reconnected. Th ...

Tips for removing the Y-Axis entirely from a CanavasJS chart

I'm working with a canvasJS chart and my goal is to completely hide the Y-Axis. I've managed to remove the Y-Axis line and title in this JSFiddle example. I came across these properties to hide the Y-Axis title and line, but I'm struggling t ...

MUI is designed to only manage either onBlur or onKeyPress, but not both simultaneously

Currently, I am working on a project with TypeScript and Material-UI. My main goal is to handle both the onBlur event and the onEnter key press event for a TextField component. Here's the scenario: I have incorporated this text field into a menu. Whe ...

Encountered webpack errors during the build process on CentOS 7 resulting in a failed nextjs

I'm facing an issue while trying to deploy a next.js application on a CentOS server. When I attempt to build it using npm run build, the following error is generated: Browserslist: caniuse-lite is outdated. Please run: npx browserslist@latest --updat ...

Can you help me figure out how to generate and output an input tag within a function?

I'm having trouble getting an input tag to appear on my webpage every time the user clicks a button. Previously, I attempted the following code: import React, { useState } from "react"; import "./styles.css"; export de ...