I'm fairly new to GCP and figured that to learn I would upload a reactJS app to a VM instance that I made. I am also pretty new to node and react so this has all been one big learning experience for me.
I'm using an Apache server and while Im aware that the index file should be on the /var/www/html/ folder, is it possible to point this default location elsewhere for this website? Here is my logic:
if I can figure this out then I can set a structure such as:
/var/www/html/website_1/
/var/www/html/website_2/
/var/www/html/website_3/
etc where I can have my domains pointing to the respecting website on the server. Am I thinking about this incorrectly?
Yes, you can put more sites on the same server behind Apache, using VirtualHost (see more examples).
Related
I'm creating a website using netlify (static html, css, javascript) as my front end and heroku (node.js) as my backend
since netlify itself has CDN I don't think there's any necessity to use cloud flare
However, as far as I know the Heroku backend runs only on one server at one place
so if I use a CDN like cloud flare for heroku will it make multiple "copies" of my server and distribute them? or am I understanding the concept incorrectly?
I'm a bit new to all this sorry in advance if I don't make sense
I recognize this question is ridiculously stupid but I need an answer to this. I have tried going through google for an answer to this, but no luck so far.
So, I am going to build an application in JavaScript (using React and Redux) with separate client and server logic. The code for each will be housed in separate files. If I deploy both my server and client code logic to heroku, how will it be deployed by heroku?
By my understanding, heroku deploys a single app, and it will see this as essentially two different apps. Do I need to write both client and server logic together and push them up to Heroku necessarily?
Without an example of what you are trying to do with your app it is quite hard to give a correct answer.
But if you want to use Heroku node.js you will be deploying both server and client logic in one project.
Here is an example for react.js: http://ditrospecta.com/javascript/react/es6/webpack/heroku/2015/08/08/deploying-react-webpack-heroku.html
I have AngularJS (1.2.16) application which works on Tomcat 8.0.x I need to add following feature: create a new tab in the application (no problem) and allows to user to select concrete from select box on previously implemented new tab, file from HDD (directory is given but outside from Tomcat) and preview (PDF file). How to connect those two worlds? I have backend also.
I have found very similar question- Simplest way to serve static data from outside the application server in a Java web application but I do not understand how to get in UI a list of files from given dir. There are any best practices on that?
EDIT: I have found also possible duplicate, so you suggest to serve all files under URL? Is it safe? Is it the only one solution?
Security considerations
Providing read/write access to a filesystem folder from an application server is always a bad practice.
It should be considered if the web application will be accessed from internet.
In case we need to handle this kind of situation the better think to do is to understand which information we need to have and to modify, and wen wrap those information inside a specific API that allow to work on strictly what we need.
Or we could have an operation approach which consists in the hardening of the server and the folders that should be accessed in a way that any threat will be contained.
The solution part
This answer was proposed for duplicate of: Simplest way to serve static data from outside the application server in a Java web application.
But this part just explain alf of the requested solution.
The answer here explain how to configure an extension of the default servlet from a custom folder in Tomcat:
You have to act on the conf/server.xml:
<Context docBase="/path/to/files" path="/files" />
Here you configure a folder in a way that Tomcat will access, and connect it to a path that could be requested on the HTTP requests (http://mytomcatserver/files/).
Now you need to configure the web.xml to connect a specific servlet to this path, to be able to handle the folder content.
Once you have your servlet and your Tomcat properly configured it's time to access the folder and files.
This could be done as explained int the answer Display list of files in webpage using servlet.
In short, you cold access the folder with plain java:
File filesFolder = new File(req.getSession().getServletContext().getRealPath("/files"));
And then with the method File.listFiles() you could get the list of files in the folder.
With File.listFiles() you could also add filters that allow you to hide files you don't want the user could access.
I'm creating a personal project, an Android application, where user sign ins via a server are essentially. Also users will be able to share important "updates" in both a data stream that all users can have access to, and potentially down the line a data stream that will be specific to local users.
Unfortunately I have basically no idea of how to implement the server for this application. I'm confident that I'll be able to create a solution though, I just need to be pointed in the right direction. Are there any existing servers/api's that I could access that will allow me to handle my "connected" tasks? If I were to make a server myself for this application where should I start?
If you have absolutely no experience with server side coding, you should start with PHP and MySQL to create a simple API for your app.
For getting started download the XAMPP bundle that has everything you need.
SQL and PHP are fairly easy for beginners. On the client(Android) side use Volley as it is simple to understand.
However if you want to get started with Node.js, your server can be up in a few minutes with express.js
I was thinking of building a web app which would be single page, using only javascript to update the page (no reloads). So I'm confused about what kind of setup to use.
I'm kinda new to both technologies, so I was wondering if you can set up nginx to serve html (+ js, css and other static resources) like a normal web server and then from those pages connect to a node.js websocket server (same host/ip) using something like socket.io?
Is this setup good or bad? What would be a better approach? What advantage would I get if I serve html pages in node.js and get static resources (css, js, images, ...) from nginx?
I dont think serving few images and static htmls from nodejs itself will ever be a bottleneck , ideally a front end proxy like nginx is required if you need to load balance between multiple servers and also for exposing you internal http services as https traffic. If you dont have that requirement it would be a overkill imho.
From various comments in the currently accepted answer, I wanted to note the following.
NodeJS itself does a pretty decent job of delivering static content, as good as nginx in many cases.
Trying to proxy a WebSocket connection is problematic at best currently, as most proxy code simply doesn't support it. Currently, it is best to use Node directly.
If/When you have a need to deliver static content separately, best to use another domain and a CDN at that point.