Deploy PeerJS server on Heroku - javascript

I have a problem with PeerJS server. I used "Deploy to Heroku" button from here:
https://github.com/peers/peerjs-server
I have no idea how can I connect with deployed cloud.
I can't find clear documentatnion about PeerJS Server.
I don't know what is the host, port, and path for my app.
var peer = new Peer('someid', {host: 'localhost', port: 9000, path: '/myapp'});
Please advice.

This how it worked for me:
var peer = new Peer('someid', {
secure: true,
host: 'your-app-name.herokuapp.com',
port: 443,
});

Your host is simply the web address to your Heroku app. For instance, if your Heroku app is named peerjsapp, then host would be 'peerjsapp.herokuapp.com'. You can find the name of your app on your Heroku dashboard. The port is usually 9000, but can be 443 if you're using HTTPS (make sure to also pass in secure:true if you're using HTTPS). You don't need to include the path unless you've changed it; if you're running the default server config, leaving out the path on your client will automatically connect. Finally, since you're hosting your own server, you don't need an ID.

• This is how I think you should do it:
const myPeer = new Peer(undefined, {
secure: true,
host: '0.peerjs.com',
port: '443'
})
• EXPLANATION:
After deploying your app to Heroku, typed 'peerjs' into the console to search for the peerjs object, from which you can navigate and find the key-value pair of
CLOUD_HOST: "0.peerjs.com"
CLOUD_PORT: "443"
The next step is just to match your own host and port with these values.
This is how I do it Console Screenshot
• NOTE:
For the secure: true part I have tried and the app works both with and without it. So it's on you to choose to include it or not. I have also found out on https://peerjs.com/docs.html this same information, check it out if you want more detailed documentation.

Related

How to run application on url website instead of port 8080

I followed the tutorials in AWS docs and using this video on youtube https://www.youtube.com/watch?v=BIQks_drQHM . What I am trying to do is route traffic to verus-ai.com and www.verus-ai.com. The only way I am able to run my application when I do yarn build and yarn serve is if I use the
Public IPv4 DNS
ec2-44-206-65-182.compute-1.amazonaws.com
with the port of 8080, essentially you can access it if you paste this into th e browser: ec2-44-206-65-182.compute-1.amazonaws.com:8080.
I want to be able to perform the same thing but with the domain I have i.e. verus-ai.com.
Domain Name: verus-ai.com
I was told from AWS support that the way everything is setup on Route 53 is correct and then problem resides on the application side.
I do not have much experiece with this part but there are 2 places in which the application is running on port 8080, specifically on the backend side
// set port, listen for requests
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}.`);
});
and the front end side
export default axios.create({
baseURL: "http://localhost:8080/api ",
headers: {
"Content-type": "application/json",
"Access-Control-Allow-Origin": "*",
}
});
should I remove the port 8080?
First, you need to create a CNAME record in your DNS that points your domain name, or a subdomain of it, to the EC2 instance: ec2-44-206-65-182.compute-1.amazonaws.com. Ideally you would assign an ElasticIP to the instance first so the IP doesn't change later if you have to shut it down for any reason.
Second, You need to change the backend to run on port 80 instead of 8080, because the default HTTP port is port 80 and that is the port that is used by web browsers when you enter an http:// address without specifying a port.

Requests to nodejs server deployed on Azure App Service timing out when trying to access Azure Postgres flexible database

I have a node.js express server deployed on Azure App Services, which connects to an Azure flexible postgresql database to serve requests. When running the server locally the postgres database can access the database fine, but when the server is deployed to an azure app service, all requests time out:
The server uses a pool to make requests, this is what my server config file looks like:
const {Pool} = require('pg');
require('dotenv').config();
const config = {
host: process.env.HOST,
user: process.env.USER,
password: process.env.PASSWORD,
database: process.env.DB_NAME,
port: process.env.PORT,
ssl: true,
max: 50,
idleTimeoutMillis: 10000,
allowExitOnIdle: true,
}
module.exports = new Pool(config);
So far I've tried:
Allowing all IP addresses to access the database
Allowing all services within Azure to access the database
Giving the server's App service contributor permissions to the database.
But none of these solutions have prevented requests from timing out, so any help would be greatly appreciated.
Thank you
I have thankfully found the solution to this problem!
I suspect that the Azure App Service overrides the PORT env variable to 8080, and so the port variable used to connect to the database ends up being wrong when a connection is attempted.
I've renamed the .env variable to something else and it is now working correctly.

Unable to connect from a different network express.js

I'm experimenting with node.js and express.js.
When I try to connect to my web server from any computer in my network, it works, but then when I try to connect from outside network the connection times out.
var app = require('express')();
var http = require('http').Server(app);
app.get('/', function(req, res) {
res.send("Hello World");
});
http.listen(3000, '0.0.0.0', function() {
console.log("Listening on port 3000!");
});
I just tested your code and I'm able to access the server from outside my local network by navigating to:
http://173.0.[my].[ip]:3000
So the code is correct. It could be that you need to open the port 3000 to the outside world. Here's how it can be accomplished.
Through your router admin interface
Here's mine for example:
Where 192.168.1.130 is the local IP of the PC I'm running the http server on.
Don't forget to click the Save settings button in that interface to apply the changes.
Using a tool like ngrok (mentioned by eddiezane)
Install ngrok through their website or without leaving the command prompt, with the ngrok node wrapper.
npm install ngrok -g
Start your http server and then run:
ngrok http 3000
Navigate to one of the url in front of Forwarding:
The free version is more for a quick test and less as a definitive way to expose a service in a production environnement since every time you restart ngrok, a new user-hostile url is given to you.
Other possible problems
It could also be that you need to add an exception to the firewall (if on windows).
To add to Emile's answer, I would check out ngrok which is an awesome tool that generates you a publicly accessible URL for a port on your local machine.
Here's a good blog post on it my buddy wrote.

Grunt hostname 0.0.0.0 access is denied

I'm wanting to view my SPA on a few different devices on my network, so in my Grunt file I changed the hostname to '0.0.0.0' as Grunt instructs, my connect task/object now looks like this:
// The actual grunt server settings
connect: {
options: {
port: 9000,
// Change this to '0.0.0.0' to access the server from outside.
hostname: '0.0.0.0',
livereload: 35729
},
Now when I run grunt serve the app opens the browser at http://0.0.0.0:9000/ however my application isn't shown, I am given the following Error:
ERROR
The requested URL could not be retrieved
The following error was encountered while trying to retrieve the URL: "http://0.0.0.0:9000/"
Access Denied.
Access control configuration prevents your request from being allowed at this time. Please contact your service provider if you feel this is incorrect.
Does anyone have any ideas on what I should do to fix this issue. I have tried using hostname: '*' but that doesn't do anything but how the same error.
I am developing on OS X 10.9.2
Thanks in advance
Setting hostname to '0.0.0.0' is correct. You can connect to your server by connecting to http://localhost:9000. Alternatively, you can use the output of hostname to connect with the machine. Optionally, you should also set the baseUrl variable in your tests to connect to
I have the same problem. It seems that the '0.0.0.0' setting allows you to call your site from outside your computer; but screws the call to the web browser asking it to load a page located in an invalid server "http: / / 0.0.0.0"
If you replace the address to the right server name instead of 0.0.0.0 it will work.
You can set your own ip address instead of the 0.0.0.0.
With this grunt launch the server on your ip. You can use your mobile to.
The livereload will work on your desktop and on your mobile.
It's not the best way if your work by team because each one have his ip address but it's good enough if you work alone.

Finding MongoDB details after hosting on Ubuntu

I'm completely new to setting up servers, MongoDB, and still a little new to Javascript.
I'm trying to upload a Deployd server onto an online server. There is limited information on this, so at the moment, I set up a simple AWS Ubuntu server by doing the following tutorials:
http://zenborgium.blogspot.com/2012/12/how-to-setup-deployd-on-ubuntu-server.html
http://terraltech.com/how-to-setup-deployd-on-ubuntu-server/
However, I'm stuck at creating the production.js. There's a guide on it here. I'm specifically stuck at this line of code:
var server = deployd({
port: process.env.PORT || 5000,
env: 'production',
db: {
host: 'my.production.mongo.host',
port: 27105,
name: 'my-db',
credentials: {
username: 'username',
password: 'password'
}
}
});
server.listen();
Where do I find the host, port, name, and credentials that I should use from MongoDB? The tutorials say I need to use my own data, but I don't know where or how to find them.
First of all, you have to have MongoDB installed. I haven't used Deployd myself, but I will give you some information regarding the config file.
If you are running Mongo on the same ubuntu server as your application, you can use localhost to connect.
Default Mongo install runs on port 27017, in other words localhost:27017.
The 'name' parameter is just a name you give your database. So here you can put whatever you want, ex my-db.
With a clean Mongo install, you don't need any credentials. You have to set that up yourself if you want. I suppose leaving them out of the config file is ok, if not needed.
Your config file should therefor look something like this:
var server = deployd({
port: process.env.PORT || 5000,
env: 'production',
db: {
host: 'localhost',
port: 27017,
name: 'my-db'
}
});
update
I had a quick look at the tutorial you linked to. In one of the tutorials they created a user for mongodb. If you followed this step, you need to put that login information into you connect-object under credentials.
update 2
To get information about your mongodb install, check this SO post

Categories

Resources