Multiple ExpressJS(Nodejs) Apps on Same Box - javascript

I've been searching for a straightforward way of doing this that wouldn't involve editing every single users' host file.
I'm going to have a couple internal apps for employees to use that are going to be hosted on the same Windows Server. I want to use a default port, but want them to be separated out so, for example if you go to
www.host.com/longrunners
you get the longrunners page. If you go to:
www.host.com/databaseMove
you get the database move page.
I'm aware that I could do this by having all of the code within the same server.js file, using app.get('/longrunners',function(res,req){}) etc for each separate app -- but I'm hoping there is a more modular solution. Maye a way to have one master server.js file that references the different apps?
Thanks!

Related

JS and CSS doesn't load on local

sorry for the newbie question, but I started my programming adventure two months ago.
I have a doubt: a client commissioned me to demo a website (so it would only work offline) and I am making the design.
Many pieces are reusable, so I have created elements via javascript to be called in the code.
The problem is that while if I start the page from the VS Code live server everything loads fine, while if I in the folder statically open an html file neither the CSS nor the JS loads. I think it is a problem with how they are linked.
My idea was to deliver a folder with all the files and I imagined that he clicking would be able to see all the components and navigate through the pages. Any solutions?
Here's an example on how I linked those JS files (it works on live server)
<script src="/components/card.js" type="text/javascript"></script>
URLs starting with a single / are absolute paths.
They are calculated by taking the current URL and completely replacing the path.
If you start with http://localhost/index.html then you get http://localhost/components/card.js. Your HTTP server will then resolve that to something like: /home/user/work/project/components/card.js and all is good.
If you start with file:///home/user/work/project/index.html then you get file:///components/card.js … which is wrong.
There are a couple of approaches you can take with this.
My preferred one is to treat websites as things that should be accessed over HTTP. There are lots of restrictions if you don't use HTTP, and these kinds of URLs just break. The simple solution is to use a web server.
Another approach is to use relative paths, in which case you need to be explicit about where you link to in terms of directories.
Going from $PROJECT/index.html to $PROJECT/components/card.js needs you to link to components/card.js but going from $PROJECT/example/index.html to $PROJECT/components/card.js needs you to link to ../components/card.js. It's a lot harder to maintain.
My idea was to deliver a folder with all the files and I imagined that he clicking would be able to see all the components and navigate through the pages.
How you deliver to a client will depend on what you negotiate with them.
In very broad terms, however, they are either going to be non-technical (in which case you should deliver them a URL and be responsible to organising the hosting of the final site) or technical (in which case they should be able to handle an instruction to test the code on a web server).

How to persist file system with Docker?

I have a project where I need to store file and persist that file. I first though about saving that file to a database. But after some reading, I notice that almost everyone recommended to use a file system to store file and keep the path to that file in the database.
I don't really want to put some cash into this, I'd really like to make it mostly local. (No AWS or Google file storage system).
I am using a React front end which makes request to a .NET Core 2.2 with E.F. back end.They are both hosted in 2 docker containers and managed by a docker-compose file.
My first though was mounting a volumes to the .NET Core container and using the System.IO function to create, save and list directories and file. It didn't worked for me...
Well, my goal is to save files efficiently and be able to read them from my react front end app. I don't know if I'm heading the right direction.
It's the first time that I'm touching to these kind of things, so if you have any recommendation, tips or whatever, go ahead. I'm here to listen and learn.
If you have a shared, bind-mounted volume that both the React and .NET core containers can access, perhaps this would work for your use case.
Take a look at the documentation for docker-compose: https://docs.docker.com/compose/compose-file/
Under the heading Volume configuration reference they give an example of two services using the same file system.

Running a python script in a Gsheet button

I want to use Gsheets to track accounts and group membership in a proprietary 3rd-party application. Right now I have a python script running on a server that checks the sheet for accounts and membership parameters and it works great. It will read the sheet and check the 3rd-party app and make sure they always match with the sheet being the source of truth.
However, I'm not really a Gsheet master. Recently I found that I can create buttons in Gsheets that will run JS code. I'm also not a JS master, however.
I actually have two questions. The first one I think the answer is yes. Can I hit outside resources like REST endpoints from these buttons?
If I am right and that can work. The second question is, can I have a JS script inside a button run a python script that I contain in the Gsheet somehow?
The reason is that this would make the entire process contained in the Gsheet for much easier distribution and adoption as it eliminates the need for ancillary resources to run the Python code.
Any help would be much appreciated!
Thanks!

ReactJS is there any way of looping through a github pages directory?

I am developing a single paged website which displays the contents of several JSON files in ReactJS. I need to loop through /json which contains the files and display these as a list. These files may change so this needs to be dynamic.
I was able to get this working using a nodeJS back end server. However my spec has changed and now this site has to be hosted on github pages, therefore the back end approach will not work. Does anyone know of any way I can access the directory in React, I have looked and cannot seem to find any way of doing this.
Thanks for any help in advance.
You cannot access any filesystem without a proxy (like Node.js) from a browser. React is just a series of literal definitions, interpreted by browsers.
You can do whatever you want with React and Github API
You can also dig in SO with [github-api] react

Meteor app linking to external pages/apps

Hi guys I'm looking to build an application that is a list of stores. One requirement is that for each store there is a special view of the store built in flash or javascript. This special view portion has been already built by someone else. It consists of a single HTML index file and a bunch of javascript/css in it.
So I think it would be very difficult to directly it as a part of the meteor app. What I want to do is to somehow have those special view portions be a separate entity from my meteor listing app. How can this be done? Will it need to be on different servers? Or can I just have two folders (one a meteor app folder, the other just those html+css+javascript/flash files) and have the meteor app have links point to the other folder? Any examples of meteor apps pointing to separate files but still function like a single webpage?
you can connect to another app by using DDP.connect() and it acts like REST API for websockets.

Categories

Resources