How to persist file system with Docker? - javascript

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.

Related

Do I need to keep uploading all files even if I make a small change on NuxtJS

I am new to NuxtJS and JavaScript frameworks in particular. To host the files on an online server I need to generate static files. Even if I make a small change on one file I have to re-upload all the files again. Is that productive? Normally I can open the server and make changes to one file and upload it. But here I have to upload all files everytime.
Yes.
Some of the reasons why:
Your generated files are not supposed to be versioned, so any changes you make there, won't (shouldn't) be committed and pushed to git.
If you change the generated files and forget to change the actual code, the next time you generate the files again, those changes will be overwritten.
It's not going to be easy at all to make even small changes directly into the generated files.
You shouldn't be making changes straight into production. Also, the changes you make there shouldn't be reflected in your localhost, so you're going to have version conflicts pretty soon if you keep doing it like that.
There is, however, a way to make all of that easier. With continuous integration/continuous deployment, you can have it all set up so for every change committed/merged into a specific branch on you version control will be built and automatically pushed to your production server.
It seems to me like you are not familiar with version control (mainly git) nor continuous integration, so here's some topics on the matter:
GIT:
Learn git concepts, not commands
5 Free Courses to Learn Git and Github in Depth
Continuous Integration / Continuous Deployment
Understanding Continuous Integration
Explain Continuous Integration Like Im Five

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

Is there a thing such as "packaged web app"?

Let's say I have a HTML/JS application, which is on a website and runs without any server-side component (except the web server, of course). So it's basically just a bunch of .html, .css and .js files (and some others, like images or SQLite databases)
Someday, an user comes to me to ask me if I can make an offline version, so they can access the app when they are offline.
My first reaction would be to provide them all the files of the app in a .zip file or something, but this is not really good: it's not "clear" to an average user, and the files and code are apparent (which could be "dangerous" if the user edits or deletes them by accident).
So I was wondering: is there a kind of format that would makes me able to store the files of the app in a packaged file?
The file would be something like a .zip file, but when you click to the file, instead of opening up the archive, it opens the /index.html (or similar) which is inside.
So for the user, it would be similar to open an .exe or a single .html file, but still that's not a native app, as that's still a browser app.
Given that I know about:
Apache Cordova; but most of the time, I just use the browser functions, and I don't have a need to use advanced native functionalities;
UWP and PWA, but I don't know if it's exactly what I want (I imagine it as a mix of website and mobile app, but I'm surely wrong);
Open Web App (a standard from Mozilla), but based on what I've read about it, it seems deprecated and not used anymore. Plus, I don't really look forward to "certify" my app... I just want to package some files.
PWA I don't think is a solution to your problem as you wont be able to redistribute the code as an executable package.
UWP would be too Windows specific and might make you lose the platform independence that you already have since you are using plain HTML and JS, plus from what I understand you would need to distribute the app on Windows Store.
I believe packaging as an Electron app would be the best solution as you can provide executable files that can be executed in almost all platforms.
Electron would be the best solution for you. I had a client that first wanted to run app on php server and eventually they figured out they need it as a desktop app. It was easy to rewrite php stuff to node and package as Electron app. You have access to everything files, system etc. so you can do more if needed.
Another solution would be to just inline everything into a single html file.

Reading configuration file(javascript file or json file) on the fly in Qml and javascript

I am new to Qt/Qml and javascript.
Let's say I have a javascript file which contains a table of parameters. The javascript file is used in Qml and it is located in the application directory. e.g. C:\Program Files\QtApp\the_table.js.
If end customer installed the Qt app, they want to manually edit the javascript file and use it with the installed application. ( No need to recompile the app source code).
How can I make it work?
I have tried to update the javascript file manually, but when I try to open the app again, the "updated entry" in the javascript file is not displayed in the application.
-----------------8<-----------------------
Updates:
Javascript file included in the qml resource will not be editable by
end user without recompiling the app.
Javascript in qml will hold mostly the logic, not the data.
It's better to use the JSON file to store the configuration data that can be modified by the end user.
Qt 5.0 and newer version has support for reading JSON file. QJsonDocument.
It sounds like the flexibility you require should be implemented at application level rather than externally. If it is just a "table of parameters" there are plenty of ways to do it in JS.
Due to implementation details you most likely don't want to bother with, that would be much preferable to updating the actual JS file.
Consider the usage of import Qt.labs.settings 1.0 which will allow you to store and make changes to settings that persist across application runs. That would be marginally easier than parsing config files. That being said, doing so is very much a viable option, you just have to interface QDataStream to QML.
That's the best I can do without knowledge of specific requirements and usage scenario.
OK, after a quick test, it seems that it is possible to import a file from the file system, you just need to:
import "file:///pathToYourExecutable/YourScript.js" as YourScript
Then you can use YourScript in QML. However, I would not recommend using this, as it invites opportunities to mess up with the application. The user shouldn't really be editing any files to make changes, just seems like bad design. Whatever it is that you want to achieve, there is most likely a better way to do it.
Solved by changing to use json file to store the data and then access the json file in QML.
The class to read the json file from the disk is JsonFile class in Qt, check this link:
https://forum.qt.io/topic/39756/qml-and-js-reading-json-file-and-change-content-on-the-go

Multiple ExpressJS(Nodejs) Apps on Same Box

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!

Categories

Resources