Jhipster - Backend URL in Angular 2 Client - jhipster

I have created a separate project ie the client and the server on different projects. How do I point the URL of my client APIs to the remote server?
ENV - Production
I'm using Angular 2

In your entity.service.js, you should have something like this :
function Entity ($resource) {
var resourceUrl = 'api/entities/:id';
simply change the last line with :
var resourceUrl = 'http://your.serveur.url/api/entities/:id';
You may have to enable cross posting if your server isn't in the same domain
https://better-inter.net/enabling-cors-in-angular-js/

you need to run jhipster-registry, clone this https://github.com/jhipster/jhipster-registry
and run mvnw and next run your microservice and gateway

Related

Get Websocket URL from Node js

I am trying to build a simple WebSockets app with node.js as a server. In order to create a WebSocket connection I write:
const url = 'ws://localhost:8080'
const connection = new WebSocket(url)
But I do not want to hardcode the URL. Can I receive it from my server?
Available options:
Using of Webpack/Rollup/Snowpack - https://dev.to/sanfra1407/how-to-use-env-file-in-javascript-applications-with-webpack-18df:
You can define a some .env and define address of server
Use dotenv or something another library on backend side to receive variable
Use Webpack/Rollup/Snowpack on frontend side to build frontend with defined address of server
It will allow to change address of server in one place
SSR (server-side rendering) - https://medium.com/jspoint/a-beginners-guide-to-react-server-side-rendering-ssr-bf3853841d55
You can provide address of server from backend to frontend

How to deploy multiple nodeJS application with different port

I'm rather new to NodeJS and I'd like to deploy the API and the application on the same server, which means same IP but on different ports.
From different search I saw it's possible but I don't know how.
Can I use Restify for this redirection ?
in this code app.listen(PORT HERE); on your two apps just define a different ports for each one.
For example
in App1 = app.listen(3000);
in App2 = app.listen(8000);
then to access each one is like :
App1 = http://localhost:3000
App2 = http://localhost:8000

Two NodeJS apps in a single gear on Openshift or a single Heroku dyno

Looking for a way to run two NodeJS apps on a single gear on Openshift Online (Premium) or the equivalent with Heroku and a dyno. Each app will live in it's own folder in the file system and have its own server.js file, listening on a different port.
Each app will have its own domain.
Each app can have its own git repo, or both apps can be in the same repo (different folder) if separate repos are not possible.
An alternate (and simple) solution would be to run each app on its own gear/dyno, but these apps are low traffic and do not justify the cost of running them separately.
Note: on Openshift, the apps run the following cartridges: nodejs-0.10 mongodb-2.4
I don't think so that would be possible because the PORT to run node app is fixed by these PaaS platforms, so, you cant run two apps on same port.
A workaround can be using vHost and cluster(I haven't tried it myself)
Write a third repo with server.js and this third repo would be bound as main repo on Heroku/Openshift
Write some shell script that runs on Post install/download of the third repo, and it downloads the other two repositories on your remote machine
And, then in the third repo use the code below
// server.js
var cluster = require('cluster');
var express = require('express');
var app = express ();
if(cluster.isMaster) {
cluster.fork ();
}
else {
app
.use( express.vhost('www.site1.com'), require(PATH_TO_FIRST_REPO_SERVER.JS).app ) )
.use( express.vhost('www.site2.com'), require(PATH_TO_SECOND_REPO_SERVER.JS).app ) )
.listen(8080);
}

access base http server of sails.js

Hi is there a way to access the base http server context of sails? I want to use binaryJS in my app and In the gettig started guide they are talking about creating the server at your own, it you have an existing express app with the following line:
var server = http.createServer(app).listen(9000);
than I could use the following binaryJS command:
// Create a BinaryServer attached to our existing server
var binaryserver = new BinaryServer({server: server, path: '/binary-endpoint'});
thank you
In Sails v0.10.x, you can access the underlying Express server with:
sails.hooks.http.server
in v0.9.x, it's
sails.express.server

Error binding socket on heroku , not sure about using express

this is my first node.js and socket.io application , i didn't use express ,I want to deploy the application on heroku do i need to use it ? i mean i just did npm install socket.io on localhost and in my server file i.e game.js i have io = require("socket.io") and socket = io.listen(Number(process.env.PORT)) only and in one of the files where from where i am sending the message i have socket = io.connect();
so please tell me if i need to use express and how show i modify my existing application ?
I have given the link to the source of application
( https://github.com/bitgeeky/herokutest )
Although the Application works fine on localhost by changing the port no , to some port no like (8000) but Heroku error log on doing "heroku open" is http://pastebin.com/MtB0z5vQ
I noticed that you haven't created a http server. I am assuming that you are creating a web application, since you are deploying to heroku. For that, you need to create a http server in nodejs.
Go through socket.io https://github.com/LearnBoost/socket.io
Also http://socket.io/#how-to-use
This should get you started
Note: You do not need express. But it will make your work easier in many ways. Depends on the type of application that you want to create.

Resources