I have a Project which I want to access from multiple IIS applications, each hosted at a different port.
Lets say, we have the following folder structure:
MyProject
Application 1 (has its server.js file and web.config)
and I have these applications in my IIS:
Website 1: hosted at http://localhost:8080 has an application
App - points to Application1 above - http://localhost:8080/App
Website 2: hosted at http://localhost:8082 has an application -
SomeOtherApp - points to Application1 above - http://localhost:8082/SomeOtherApp
How do I get the IIS Application host info in the server.js file, just like I can get the port info by using process.env.PORT?
I need the application name info ( /App or /SomeOtherApp ) and the host info (localhost:8080 or localhost:8082) in the server.js file before i start the app.
I know that we can get app this info from req.headers once the app starts, but i need it before the app starts. And since the web.config is also common to both applications I cannot set these there.
Can we get this information from IISnode?? If not, is there some other platform which can give me this information in the server.js file?
Thanks.
Related
As per my Title, I want to deploy Node.js & React.js projects in the same domain and server.
Basically, I want to host the application on cloudways server. https://www.cloudways.com/
I try to host there but due to the same domain action, it is not working as working in the local environment.
Front-end screenshot with package.json script structured(React.js): https://prnt.sc/xT4NAPxt0S99
Back-end screenshot(Node.js): https://prnt.sc/mSg_H4O6prF0
The given screenshot is from a local machine.
As you see here https://prnt.sc/xT4NAPxt0S99 we are using npm run build and after doing the build, we move that folder to the server folder and run npm i && nodemon index.js. It is working well in a single domain or IP in the local server well. But when I do the same process on a live server, it is not working.
Why I am using cloudways server?
For this, I don't need to install and set up MySQL, Node modules, PHP, and other things. Cloudways is doing all things when we create a cloud server.
npm i don't need to run this company on a server.
I'm fairly new to MERN and we're trying to deploy an app to DigitalOcean with one main domain and 2 subdomain.
we have the following setup for our app.
Three separate repos:
Api (backend server for reading writing data)
User (front end for users of our app)
Admin (back end for admins)
We have 3 domains / subdomains registered in the following format:
domain.com (user)
admin.domain.com (admin)
api.domain.com (api)
Questions:
How do we setup the droplet to accommodate this configuration? (user and admin side should point to api server)
How do we deploy to the three separate repos from github to the one droplet while respecting the corresponding domain / subdomains?
Other considerations:
Do we need to use Nginx? Pm2?
We will be using mongodb as our database.
Thank you!
I would suggest you to use Nginx as a web server. PM2 would not be a choice because it's not probably a server by itself.
Refer Nginx Docs here
We want to host the application on IIS server. We need it to support dynamic routing.
We tried downloading IIS node and we're not sure how to proceed.
Is there a file that needs to be loaded and needed to run, such as server.js?
You will need to install nodejs on the host system and have server running on a port, then use IIS as a reverse proxy on top.
This article goes into detailed steps on how to get there - https://alex.domenici.net/archive/deploying-a-node-js-application-on-windows-iis-using-a-reverse-proxy
I head to create Nuxt SPA with routing and mb API in future like that:
Backend server (on express or smth else) listen and on request give entire SPA to client.
Now user can use everything on client side (include routing) with no more else requests to backend (mb API requests only)
It means that server should give some .html file with js and css files as SPA and it will work on client side.
I tried to run some commands like nuxt build and nuxt generate
It looks like they return a same result - js files couldn't be found
And index.html file doesn't work properly
After some researching I found a solution
But now I got this:
It can't open the fourth js file in another js file. Path isn't right!
Every time I tried to run it as a static html file and from localhost (and also with using Live Server)
I think I did a lot of crutches and there should be another built-in function or feature that allows us to do what I want
I wrote a lot - if I made a mistake or you didn't get smth - please, ask! I need any help
To test your locally built application, you need to serve all files within the generated /dist folder. You can setup very easily a local web server using Express/Node.js as you already have Node.js installed when running Nuxt. Create a new folder and install express via npm (run npm install express).
Then, copy everything from /dist into /public and create a file server.js:
const express = require('express');
const app = express();
app.use(express.static(__dirname + '/public'));
app.listen(3000);
Run the web server with node server.js and you can access your generated files on http://localhost:3000.
Learning nodejs and started to created my own restful API using restify.
I have created a very simple server.js file which contains basically a hello world type example starting up like:
server.post('/api/messages', servicemanager.verifyFramework(), servicemanager.listen());
server.get(/.*/, restify.serveStatic({
'directory': '.',
'default': 'index.html'
}));
server.listen(process.env.port || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
which works fine locally. I cant hit http://localhost:3978 and I can test my API calls just fine calling http://localhost:3978/api/messages.
I have deployed my code into bitbucket and now I want to host these APIs in Azure using App Services.
My project structure is like so:
/topfolder
-/myproject
-/node_modules
-/node_modules...
server.js
package.json
index.html
When I setup the new app service in Azure, I can see that the deployment receives the code from BB, but the service never responds to my requests.
I have setup the home path of the app to live in: /site/wwwroot/topfolder/myproject and I can see the index.html when I navigate to http://myproject.azurewebsites.net so thats good.
I actually get a 404 error:
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
There are heaps of examples of how to setup continuous deployment using bitbucket and for the most part, they all seem to work, but my server.js file doesnt seem to be the getting called or starting up.
How can I debug whats going on here?
Is the packages.json file used in this scenario by Azure?
Thanks.
As the root directory path of the application hosted on Azure App Services, is D:\home\site\wwwroot. And about the nodejs application, the Azure fabric will find the entrance script in root directory like server.js. And the requests are handled via web.config in root directory. If there is missing server.js or web,config file, you will occur 404 error.
You can try to modify or your application's structure, like to:
-/node_modules
-/node_modules...
server.js
package.json
index.html
Then, you deploy your application to Azure via GIT or from BB, the Azure deployment task will run command npm install and generate the web.config wile in the root directory.
Any further concern, please feel free to let me know.