http get from assets not work in published app - json

In angular app I have assets/config.json file and I am want read file this while inialisiang app.
When run with ng serve locally I can access file with http://localhost:4200/assets/config.json
But when I hosted app in IIS on server, getting 404 error for URL
http://my-web-server/assets/config.json.
When run with ng serve locally I can access file with http://localhost:4200/assets/config.json

simply don't use full path
just relative one: ../assets/config.json

Add "assets/config.json" into your angular.json file into assets array under architect->build->options->assets

Related

Deploy and host .net core 2.0 and angular 6 app

Intro:
Currently, I have two separate projects.
One solution is for .NET core Web API 2.0 and another project is Angular 6 app.
I have a problem deploying this to my hosting provider ( asphostsportal ).
It consists of one root folder httpdocs where when I publish my API I copy contents of publishing folder.
After transferring files via FTP I confirm that my API works by sending a request and getting the response.
Now I need to publish my angular project.
The simplest way to do so is with ng build and I get some folder in dist.
Problem:
If I transfer contents of the folder inside dist to my root folder httpdocs on server It can't find any page but API still works.
If I transfer the whole folder inside httpdocs and set server Host setting to define document root to that folder:
It will find the index.html and show me my landing page.
However then API won't work.
If I leave it as is and change the document root back to httpdocs ( where the API files are ) but push the index.html from httpdocs/website to httpdocs ( in this case I also edit index.html to point to website folder for resources etc ) in the hope it will find it ( server IIS setting )
It doesn't. After that my API starts working again. However, no landing page to be found.
Just FYI I do not have any extra startup.cs lines of code that have anything to do with static files nor did my publish command on API project create wwwroot folder ( like mentioned here)
Edit (Solution):
Okay, so I got it to work.
1) I added 2 lines of code in Configure method of Startup.cs in my API
app.UseDefaultFiles();
app.UseStaticFiles(); // For the wwwroot folder
Where according to MSDN
"With UseDefaultFiles, requests to a folder search for: index.html"
2) I manually added wwwroot folder which for some reason was not generating upon publishing command for my API project.
3) In that folder I copied all contents of my dist/website angular publish files
And now it works, cheers!

How to add package.json file to built react app?

If use npm build command to build a react app for production environment, we can get a build named folder. There are html, css and JavaScript in it, but the package.json file doesn’t exists.
If we use this file to set http proxy endpoint to connect API, we can’t run the app well because the endpoint can’t be found.
How to deal with this json file rightly in this case?
First if you have package.json of some Node-React application you can run in example windows CMD (terminal console) and make some folder there you put this package.json and navigate to this folder and then, there typing npm install. On this away you can prepare all what is need for this Node-React app. Exactly with this command starting make node_modules folder there stat install need package. Next step is make folders: src and public, there you put next file :
on Src folder App.js, index.js, App.css
on public folder index.html.
That is because in this package.json exists all what is need for starting application, but if you menually build package.json this can make with run npm.
init in CMD.
Use Proxy in package.json file you can use for example if you send some data in case client-server app. There you have in client for HTTP request axios, on server side express. In package.json file add row "proxy":"http://localhost:3001"
from server. For that plz. look How to set port for express server dynamically?

Not able to load images and json files locally in react js with HTTPS=true in react app

I have created a react app using create-react-app and running it using command
set HTTPS=true&&npm start. Also, I'm using the axios for AJAX call.
In the app, I want to use the mock data from the JSON files which are in the local directory under the src/shared/mockdata folder but somehow I'm getting the 404 error/ Cannot GET /assets/logo-80x80.png though I have given the full path https://localhost:3000/shared/mockdata/current.json and this same thing is happening with loading the images as well.
I used npm run eject and tried it by setting the value false of disableDotRule of histodisableDotRuleryApiFallback in webpackDevserver.config.js file.

How to get the all the files(their file paths) in a folder from a web directory?

I'm trying to make a UWP file browser app that show all the files from http://192.168.201.254/media/, to do that I need to get all the file paths under http://192.168.201.254/media/, is there a way to do it?
Clients can only request known file URLs via HTTP.
The server can be configured to spit out an HTML file list as default page for the directory and you can process that on the client side.

Heroku Node server: Possible to just serve plain HTML pages?

I was wondering if I could just upload a bunch of HTML (or any) files and have them reachable by URL, without specifying the routes, the static files, etc. The app is NodeJS/ExpressJS app, but I would like to serve some files and folders from that app like regular HTML pages.
Sure, just configure your directory as an Heroku PHP application by doing:
$ touch composer.json
and pushing that to your application. Heroku will now see your app as a PHP app and serve it directly, even though you only have static files.