Using gulp I have:
browserSync.init({
proxy: "localhost:8080",
open: false
});
this allows me to go to http://localhost:3000 and the request goes to the backend on port 8080.
Now my app is split into two backends, so I have part of my app on port 8080 and the other part on port 1212
how can I tell browsersync to proxy http://localhost:3000/module1 to port 1212 and anything else http://localhost:3000/* to port 8080 ?
Thanks
based on this answer I was able to make a small change and fixed this issue using:
var url = require('url');
var proxy = require('proxy-middleware');
var proxyOptions = url.parse('http://localhost:1212/api');
proxyOptions.route = '/api';
browserSync.init({
proxy: {
target: "localhost:8080",
middleware: proxy(proxyOptions)
},
open: false
});
this means that all requests going to http://localhost:3000 (default browsersync port) are proxied to 8080, but if any path of the request starts with /api, then it goes to http://localhost:1212/api
Related
I am attempting to connect all browser traffic through my SOCKS5 server, but have had no luck so far. I have read the docs, e.c.t
I am trying to get something like this working:
https://github.com/txthinking/socks5-configurator/blob/master/options.js
Here is my current code:
var config = {
mode: "fixed_servers",
rules: {
proxyForHttp: {
scheme: "socks5",
host: ip,
port: port
},
bypassList: ["mygeoip.co"]
}
};
chrome.proxy.settings.set(
{value: config, scope: 'regular'},
function() {}
);
For some reason it does not connect, it does not do anything. I have managed to get an http server running in the past with a pre-loaded PAC script, but this does not work.
Big up vote to whoever can help me out.
I am using socket.io to display a message but when I run node server.js it does not console log any of the output message. I have attached my chat.html, server.js and main.js file to show the socket.io code.
chat.html
<script src="http://localhost:54159/socket.io/socket.io.js"></script>
<script src="js/main.js"></script>
server.js
const http = require('http');
const express = require('express');
const socketio = require('socket.io');
const app = express();
const server = http.createServer(app);
const io = socketio(server);
app.use(express.static(path.join(__dirname, 'public')));
io.on('connection', (socket) => {
console.log('New web socket connection...');
socket.emit('message', 'Welcome to Chat Room!');
});
const PORT = 54159 || process.env.PORT;
server.listen(PORT, () => console.log(`Server running on port ${PORT}`));
main.js
const socket = io();
OK, I guess I'll summarize the recommended changes our exchange in the comments:
Change this:
<script src="http://localhost:54159/socket.io/socket.io.js"></script>
to this:
<script src="/socket.io/socket.io.js"></script>
That removes the need for you to specify the port (which was incorrect anyway).
Change:
/public/chat.html
to:
/chat.html
so that it matches up with where your express.static() line is looking. For /public/chat.html to work, chat.html would have to be located in public/public/chat.html on your server's hard drive, but I assume it's not and it's likely in public/chat.html. Your express.static() line is pointing at public so that's the top of the tree it looks in. Any other paths in the URL are relative to that.
And, anytime you make a change in client or server code, make sure and restart your server to make sure all recent changes are being used.
If you're unsure at all about what port your server is running on, then look at the results of this when your server starts up:
console.log(`Server running on port ${PORT}`)
That will tell you port its running on. The brackets log reference to a port is probably brackets connected to the nodejs debugger which will be on a different port from your web server.
I have a part of my website (react-app) that wont render when pushed to heroku, but it runs fine locally.
The heroku domain is https://notmicahclark.herokuapp.com/
it uploads successfully to heroku no errors
my repo is https://github.com/Scharite13/NotMicahClark.
the page is the /art page.
the code related to it is the art.js file and the images are in the public, and the object is on art_database.js
You've generated your build folder once. You've since done changes to your code but haven't generated a new build.
const express = require("express");
const app = express();
const port = process.env.port || 5000
app.use(express.static(path.join(__dirname, 'build')));
app.get('/*', (req, res) => {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
app.listen(port, () => console.log(`Server started on port: ${port}`));
here you can see that you are only serving the content which is in your build folder. It hasn't changed.
Go into your clients folder and execute npm build and move the generated build files into /build.
I'm working on localhost and I'm trying to use browsersync. I want to point it to my root directory, which is http://localhost:8080/site/
What should I write here:
server: {
baseDir: ""
}
I tried ./ but didn't work.
It keeps redirecting me to http://localhost:3000/ and getting this message: Cannot GET /
Here is my whole code:
browserSync.init({
server: {
baseDir: ""
}
});
Using baseDir won't work in combination with PHP (takes only a static site)
Try proxy instead like the others suggested, and set a port.
Here's the code snippet:
browserSync.init({
port: 8080,
proxy: "http://localhost:8080/site/"
});
Note that it's not under 'server' anymore, like the code in your question.
I want setup a simple webserver using JSON API(I Followed this tutorial).I have in this directory (C:\xampp\htdocs\server) 2 files:
server.js
node_modules(folder)
server.js
var express = require('express');
var app = express();
app.listen(3000, function() {
console.log('Chatfuel Bot-Server listening on port 3000...');
});
app.get('/*', function(req, res) {
var jsonResponse = [];
jsonResponse.push({ "text": "Hi. " + (Math.random() * 5 + 1).toFixed(0) + " is a lucky number..." });
res.send(jsonResponse);
});
So what is happening in the background?
After launched via terminal: node server.js
If the server gets a request it invokes code lines 8 to 12.
But it doesn't works! why?
Screens and more info here.
The problem is that you're serving node from your local computer, and the chatbot testing service is trying to connect to that running instance of node, and it cannot connect to your localhost.
In the example, they've used digital ocean to deploy the node application. Therefore, the running API is available at some real IP address.
So, if you want to do what they've done, deploy your node app somewhere and expose that particular deployment's IP to your testing framework, and then it should work.