Is it possible to expose nodes localhost to my host? - javascript

I am currently working on an Ionic based project. due to the fact I don't want to install node.js locally I tried DDEV, even it is supposed to be a PHP development environment.
However, when serving my application via ionic serve -l the frontend of my app is built and should be accessible (within the container) on http://localhost:8200. Well, I have to expose this port to my host I guess.
To do so I already tried a few configurations, but nothing worked out. For example:
I configured the nginx-site-conf for listening on port 8200. A weak try, I know but I had to try.
Furthermore I created a docker-compose.override.yaml and added the port 8200 to be exposed to my host. Didn't work out well.
Has anyone an idea or is DDEV just not the right tool for that job?

You'll want to do a docker-compose.extraport.yaml (name of the file is arbitrary) that exposes that port to the host.
I tried this .ddev/docker-compose.extraport.yaml and it worked fine. I just tested it with nc -l -p 8200 inside the container, and telnet localhost 8200 on the host.
version: '3.6'
services:
web:
ports:
- published: 8200
target: 8200
Details about adding extra docker-compose files are at https://ddev.readthedocs.io/en/latest/users/extend/additional-services/ and https://ddev.readthedocs.io/en/latest/users/extend/custom-compose-files/ - those are mostly aimed at people creating a completely new service, but it all works the same for overriding as here.

Related

I want to deploy Node.js & React.js projects in same domain and server

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.

npm build a vue app and run it on a raspberry Pi

I am creating a Vue app with my roommate and we want to deploy it on our raspberry Pi.
Is there a possibility to npm build our final app on our PC and just start the server on the Pi without having to build the app on the Raspberry? And if so, how can we start the app on the Raspberry?
Thank you in advance!
Totally possible. Build your vue app on your PC (known as development environment) and host it on you raspberry pi (production environment). There multiple ways to do this, but from a high level perspective you just need to:
Set up you pi like normal by installing the preferred OS
SSH into the pi from your PC
Install a webserver. For Vue a quick fix could either be Nginx or Apache
You can install both Node and Git on the webserver through SSH. Then you can git clone the app right into the correct folder. Then with Node installed on the server you can run your npm commands like normal and build the Vue site on the server with npm run build. Otherwise you can just copy your build/dist folder to the server, but then you might need to do some extra configuration.
Get a domain name and point it to your raspberry pi's IP (https://www.noip.com/ is a good free choice I think)
A good list of tutorials to follow is:
How to set up SSH on a raspberri pi
How to set up Nginx or Apache on a raspberri pi
How to deploy a Vue app to a webserver (check both Nginx and Apache). There are some good videos on youtube to check out
Pointing a domain name to my raspberry pi website
NB: One last very important thing to remember is that if you're going to expose your webserver to the internet via your home network (using your own internet at home), you might expose your router to the world, which could enable malicious actors to get into your PC and any other device connected to your network. You might need to think about installing a firewall to prevent this. So maybe check out some research on that too.
Here are some useful links:
https://www.instructables.com/Host-your-website-on-Raspberry-pi/
https://medium.com/#thesabareesh/host-your-own-website-on-a-raspberry-pi-3-e3c8fdb90f90
The result of a vanilla Vue build is a dist directory containing static files.
You can serve them over the network using a static file server: Nginx or Apache for example. The latter I believe is preinstalled in the Raspberry Pi OS and a lot of other distros.
You can also follow this guide as a starting point for Apache.
Also the Vue docs have a page dedicated to deployment.

Strapi deployment

I am new to Strapi and I found it really good, I got my website in development mode locally working perfectly fine but I can not get my head around or find any good guide how to host Strapi on Debian Linux server, that I have, to be part of website and to access Strapi control panel for example mywebiste.com/admin so I can add content as blog posts directly by logging in to website admin part. Is that possible or I must use some services like Heroku. if someone can provide in short step by step what to do I will really appreciate that. I tried already create new Strapi project inside public_html folder but its not working
I use strapi on my project . I hosted strapi on pm2 package. Its very easy.
this documention https://docs.strapi.io/developer-docs/latest/guides/process-manager.html#install-pm2
don't forget add startup Ubuntu to pm2. Otherwise when Ubuntu started then not starting pm2
I suggest use Ubuntu.
Nginx Configuration
In order to deploy it to a Linux server, you need to install nginx, and set it up. You can find instructions in official documentation: https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/deployment/optional-software/nginx-proxy.html#nginx-virtual-host

How to solve "Access-Control-Allow-Origin"-Issue in vue.js?

Im new to vue.js and webpack. I currently have a very big trouble to archive the next step: communicate with real-world-apis in a dev env.
what i currently do is:
npm run dev
my application calls an remote api to which i have no access.
then i run into the Access-Control-Allow-Origin-Issue.
If i build my application and run it with xampp everything works fine.
What can i do, to simply develope my application instead to hassle with that security thing?
I have tried to create a proxy, so i have already looked at:
npm cors (node-cors-client and node-cors-server) - but how does that apply to my vue app?
socket.io - but it seems to be overkill
http-server - but i got the same issues here
nuxt - could work, but then i need to refactor my vue.js app to nuxt and i dont know if this works then
any suggestions? Thanks!
Solved:
I ended up with a PHP-API
The PHP-API runs with xampp under port 80
The Vue.js-App runs with npm dev server under port 8080
The CORS-Hassle must solved then in the PHP-Script with:
https://stackoverflow.com/a/9866124/3918455

Run sails.js with least privileges in Production

I'm using Sails.js 0.10.5 on Node 0.10.33 on Ubuntu Trusty. I'd like to execute the node process as a non-root user with the least possible privileges in the production environment. I'm comfortable with the various options for binding to ports below 1024 but I'm more concerned with directory permissions.
Ideally, I'd prefer the node process only have write access to its log files and nothing else. It should only have read access to the directory containing app.js and below.
At the moment I have needed to grant write access to the ./.tmp directory and also to the ./views directory due to the grunt tasks that run at startup. I'd rather perform the grunt tasks at deploy time as a different user instead of at run-time. The sails www command appeared promising but I couldn't get the desired outcome.
Can someone please point me in the right direction for running Sails.js with zero write access to its assets, views, etc?
Use sails www to build static assets
chmod -R 440 all files and directories, so that your user and the webserver (group) can access the files.
Use nginx/apache to host a webserver on port 80/443 and proxy requests to sails (running on its own port or over a unix socket).
Run sails using PM2 to keep it running and have it manage/collect logs.
Sails will lift, but will be unable to write its .tmp directory, which shouldn't even be necessary since all your static files will be routed to the www directory through nginx/apache.
The simplest solution to me seems to be to separate the grunt tasks that need the elevated privileges out into a separate file that you can call with a different user on deploy. Then sails won't need to run anything and can be read only.
EDITED: I use PM2 with apache as proxy ( with mod WS ).
You can use one proxy like apache to route from port 80 to others internal server ports based on host.
With this way you can run multiple apps in same server.
It has a lot of usefull functions like see the logs how varius apps in terminal, restart and log crashed apps, run app as user, app status ... etc .
Pm2 link: https://github.com/Unitech/pm2
PM2 configs: https://github.com/Unitech/PM2/blob/development/ADVANCED_README.md#options

Categories