Deploy and host .net core 2.0 and angular 6 app - angular6

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!

Related

Hidding Servers Filesystem in Gatsby / ReactJS?

I am about to learn ReactJS.
I want to hide the filesystem structure of my server and only show the project root.
If i go to inspect tools in google-chrome i can see where my project is located on my C: Drive.
Wasnt able to find something about it and Ive got no Idea.
Hopefully, someone can help me.
This is because you are using your computer as a server to serve your site so the inspect tools are able to recognize the origin of the code, assets, and images.
Locally, even using gatsby develop or gatsby build (and gatsby serve) you will always be able to see the root of your project, it happens with all web development files, not only in Gatsby.
In a real scenario, where it's a server (with a domain attached, not your PC) that serves the files you will never see the origin because your site will be placed in the /public or /www of your server. To prepare your project to be deployed, you should run gatsby build command, which will create a /public folder in the root of your project with your code compiled, that folder is the one that needs to be deployed.
This is normal in development environment, for deploy your project try one of these approach in root of you project:
npm build
or
yarn build
This command build an optimized version of your project in build folder, after you can upload content of this folder to your www/plulic folder of your server,

Firebase not running index.html file

I'm a pretty new programmer going through the Firebase tutorial. I have gone through steps 1-5 of the tutorial (https://codelabs.developers.google.com/codelabs/firebase-web/#5). I've added the "Add Firebase to your web app" js code to the html file, and set up the Firebase CLI. However, when I run the firebase server, everything seems to work other than it is not showing the code from the index.html file.
I am in the right directory, and my console says "Server listening at: http://localhost:5000." But, at localhost 5000, it shows a generic "Welcome to Firebase Hosting: You're seeing this because you've successfully setup Firebase Hosting. Now it's time to go build something extraordinary!" box rather than the app interface code in the index.html file. It is the only html file in my directory. It seems like I am missing something very simple. Thank you for your help.
The website shown to you is the index.html from your public folder (or whatever you configured it to be in your firebase.json file).
The culprit might be firebase init. It tries to generate a generic index.html file for you. However, in the latest version, it should at least ask you whether or not to override (which it did not in the past!).
The problem is firebase init being unbelievably crude. It just overrides the index.html file that was in your public folder... no confirmation, no safety net, no nothing.
If you lost, or accidentally let firebase init overwrite, your index.html file, you have to re-produce it somehow. If you do not have a backup of or other means of re-producing your index.html file... well... too bad!
How does the firebase CLI work?
Generally, the steps of a firebase setup go a little like this:
firebase login
firebase init
your-build-command-here # (if you have a build pipeline)
firebase deploy
You only need to do Step #1 (login) the first time when you setup building on that machine (or maybe when a new firebase revision has been released)
You only need to do Step #2 (init) to initialize a new project. That is, when you don't have your firebase.json yet (which will be created by the init command).
To re-deploy, it's simply:
your-build-command-here # (if you have a build pipeline)
firebase deploy
I figured out my answer. The index.html file that was being posted was in the "public" file, which was created during the "firebase init" stage. I replaced that placeholder html file with the one for my app.
Firebase hosting not showing up app?
There might be two reasons for this problem
1st step:
Make sure your public folder (define in your firebase.json) 'dist' containing the index.html hasn't been modified by firebase init command, if yes replace it with your original project index.html
for reference (dist is standard but your may different)
{ "hosting": { "public": "dist"} }
2nd step:
Make sure to configure your base href in project's index.html
as
<base href="https://["YOUR FIREBASE PROJECT NAME"].firebaseapp.com/">
and other bundle files as
<script type="text/javascript" src="https://["YOUR FIREBASE PROJECT NAME"].firebaseapp.com/runtime.a66f828dca56eeb90e02.js">
<script type="text/javascript" src="https://["YOUR FIREBASE PROJECT NAME"].firebaseapp.com/main.2eb2046276073df361f7.js">
3rd step run command - firebase deploy
enjoy ! ;)
New projects
when doing firebase init select the directory which contains the index.html as the public directory.
Existing projects
update firebase.json with
"hosting": {
"public": "dist/directoryThatContainsIndexHtml",
......
}
Edited Original Answer: Available in edit history. Only for testing purposes.!! for production, use the updated version. Contents of dist are rewritten on each build so anything you place #dist are gone each time you build.
For anyone else comming across this.
Try launching in incognito mode - the browser was cached for me.
https://stackoverflow.com/a/56468177/2047972
first of all you need to check your index.html after deployment of project. after these command steps:
firebase login
firebase init
firebase deploy
your real index.html file might be overwrite by firebase generic file that's why the problem is occurred. so change code of index.html after deployment of project. if you see this box on your web page
Tip: copy your complete project anywhere in your PC before deployment.
otherwise check your directory for file path your path of index.html is must correct.
In my case when I run the command ng build --prod it created a sub folder under dist folder. Assume my project name is FirstProject. I can see a sub folder called FirstProject inside dist folder (dist/FirstProject).
Give dist/[subDirectory] as your public directory
What do you want to use as your public directory? dist/FirstProject
This solved my issue
For deploying Angular application to Firebase simple and quick tutorial
you can find here.
During the process of firebase init, type N, when the question
"File dist/index.html already exists. Overwrite?" appears, and your page will be displayed as it should be.
In public folder option write dist/your-folder-name.
This will allow you to render your index file which is in your folder.
npm install -g firebase-tools
firebase login
firebase init
firebase deploy
firebase open
Select the following after scrolling down
Hosting: Deployed Site
When you build your Angular app, at least with Angular 10, by default Angular creates a folder names dist, containing a folder having the name of the application. For example, this example’s app is named blog-front, so when building the project (ng build or ng build -- prod), Angular will create a folder dist, containing a folder named blog-front:
When you reach the firebase init step asking the public directory, your folder's name should be “dist/blog-front” for this example, or “dist/yourApplicationName” as a general rule :
In my case firebase was using the wrong directory, also see here: firebase CLI didn't recognize the current project directory for 'firebase init'. While I was expecting firebase to put all created files into my project directory it was totally disconnected and put all files into my /Users/MyUserName directoy and deploying the wrong index.html from there.
This is how to fix it (no reinstall of firebase needed as suggested in the linked post):
delete all created firebase files from /Users/MyUserName directoy (.firebaserc, firebase.json, index.html and dist-folder)
run firebase init on project directoy
use dist/projectname as public directory
Configure as a single-page app "Yes"
do not overwrite index.html (if you do, make sure to "ng build" again before deploying)
firebase deploy
By the way, for everyone who is using Angular 7, this tutorial about deploying an angular 7 app to firebase hosting was really helpfull to me.
I faced similar situation. When we run firebase init it asks couple of questions. At that time we mention the directory path from where firebase will take all files to deploy.
Make sure that, directory contain index.html.
Delete the index.html which is present in dist folder.
Then run the following commands:
firebase login
ng build --prod
firebase init
firebase deploy
This Worked for me
First Stop the project and follow these steps
npm install -g firebase-tools
firebase login
firebase init
? Are you ready to proceed? Yes
? Which Firebase CLI features do you want to set up for this folder? Press Space to select features, then Enter to confirm your choices. Hosting: Configure and deploy Firebase Hosting sites
? What do you want to use as your public directory? dist
? Configure as a single-page app (rewrite all urls to /index.html)? Yes
After initialization is completed makesure to delete the created dist file before next steps
ng build --prod
firebase deploy
You are seeing this error because you didn't run the command:
npm run build
make sure you use it before firebase deploy
and also make you are incorrect directory.
execute this after finishing firebase init process.
If you get a public folder with ready index.html by firebase init. You can simply replace that index.html with yours and use the command:
firebase deploy
That should be enough to get it working. Make sure all the files are where they should be!
Working Solution
Just do
flutter build web, then
flutter deploy.
firebase init tries to generate a generic index.html file for you, and if it did that, then you first have to do flutter build web so that the index.html you need is generated, rather than the generic one, and then again flutter deploy
Please follow the step
npm install -g firebase-tools
If you already have a dist folder, remove it from directory
firebase login
ng build --prod
firebase init
firebase deploy
index.html file has that firebase default information.That's why it is showing that information. Copy and paste index.html from your original angular file and paste it to dist index.html. This fixed my issue.
You should add your files to public directory folder before deploy it into firebase server(your app's index file should be there).
My solution is just waiting a bit.
Then, if it still not working.
let try:
Solution 1: check your index.html inside "build" folder and index.html in your own project. They should be the same, if not, copy code index.html outside "build" folder and paste into index.html inside "build" folder.
solution 2 : delete your .firebase folder. and init it again.
=> firebase init
? What do you want to use as your public directory? build < == NOTE: "build" is my directory
? Configure as a single-page app (rewrite all urls to /index.html)? No <== select NO
? File build/404.html already exists. Overwrite? No <== select NO
? File build/index.html already exists. Overwrite? No <== select NO
After doing these things, I also get that notification of "Welcome Firebase Setting Host Complete" , and I just wait for a while. then reload the website.
Changing the default HTML page name in the public folder to index.html worked for me.
Also, make sure you do not rewrite the index.html when firebase prompts you to in the firebase init step(follow the attached image).

Subdirectories in openshift project cannot be found

I built a site using a php openshift project and accessing the root directory via http works fine. However, all the root directories give me a 404 not found, like this one: http://test.toppagedesign.com/sites/
I checked with ssh, and /app-root/repo/sites and app-deployments/current/repo/sites/ both exist.
EDIT
Added a directory called php and now I have 503 errors for everything...
EDIT 2
I deleted the php directory, now the 503 errors are gone. However, I do still get 404 errors for the subdirectory.
Here is my directory tree: http://pastebin.com/hzPCsCua
And I do use git to deploy my project.
php is one of the alternate document roots that you can use, please see the March Release blog post here about this (https://www.openshift.com/blogs/openshift-online-march-2014-release-blog)
As for the sub-directories not working, can you ssh into your server and use the "tree" command to post the directory/file structure of your project? Also are you using Git to deploy your project or editing files directly on the server?
You need to have an index.php or index.html file in any directory that you want to work like app-domain.rhcloud.com/sites , if you just have sub-directories, how would it know what to show? Also, indexing (showing a folders contents) is not enabled for security reasons, and I believe there is no way to enable it.
This sounds like it could be a problem with how you are serving your static content.
I recently created a new sample app for OpenShift that includes:
a basic static folder
an .htaccess file (for serving assets in production)
support for using php's local server to handle the static content (in your dev environments)
Composer and Silex - a great starting point for most new PHP apps
You can serve the project locally if you have PHP-5.4 (or better), available in your dev environment:
php -S localhost:8080 -t static app.php
For a more advanced project that is built on the same foundation, take a look at this PHP+MongoDB mapping example. I wrote up a blog post with some notes on my process for composing that app as well.
Hope these examples help!

Openshift: where to put resource files that I want outside of the deployment folder

I'm starting a new web app with Openshift (jboss, mysql). It's the first time I use openshift and after reading through some doc and experimenting a bit with it, I'm having one question regarding best practices for the architecture of my app.
There will be some files generated by- or uploaded to the application (resources). I'd like those files to be outside the deployment folder so they are not erased/overwritten when the app deploys again. I have browsed through the directories and I was wondering:
is it ok to use the /var/lib/openshift/[openshift-id]/app-root/data folder for these files?
Yes, you should use your ~/app-root/data folder for any files that you want to not be erased when you do a git push, there is also an environment variable that you can use that points to that folder called OPENSHIFT_DATA_DIR. Please note that if you are using a scaled application, that folder is not shared among your gears.

Deploying just HTML, CSS webpage to Tomcat

I am just getting started on developing a website. All I have at the moment is a HTML page supported by a couple of CSS stylesheets.
Can I create a WAR file from the HTML and CSS pages? How do I deploy them on to a Tomcat server?
Thanks.
There is no real need to create a war to run it from Tomcat. You can follow these steps
Create a folder in webapps folder e.g. MyApp
Put your html and css in that folder and name the html file, which you want to be the starting page for your application, index.html
Start tomcat and point your browser to url "http://localhost:8080/MyApp". Your index.html page will pop up in the browser
Here's my setup: I am on Ubuntu 9.10.
Now, Here's what I did.
Create a folder named "tomcat6-myapp" in /usr/share.
Create a folder "myapp" under /usr/share/tomcat6-myapp.
Copy the HTML file (that I need to deploy) to /usr/share/tomcat6-myapp/myapp. It must be named index.html.
Go to /etc/tomcat6/Catalina/localhost.
Create an xml file "myapp.xml" (i guess it must have the same name as the name of the folder in step 2) inside /etc/tomcat6/Catalina/localhost with the following contents.
< Context path="/myapp" docBase="/usr/share/tomcat6-myapp/myapp" />
This xml is called the 'Deployment Descriptor' which Tomcat reads and automatically deploys your app named "myapp".
Now go to http://localhost:8080/myapp in your browser - the index.html gets picked up by tomcat and is shown.
I hope this helps!
Here's my step in Ubuntu 16.04 and Tomcat 8.
Copy folder /var/lib/tomcat8/webapps/ROOT to your folder.
cp -r /var/lib/tomcat8/webapps/ROOT /var/lib/tomcat8/webapps/{yourfolder}
Add your html, css, js, to your folder.
Open "http://localhost:8080/{yourfolder}" in browser
Notes:
If you using chrome web browser and did wrong folder before, then clean web browser's cache(or change another name) otherwise (sometimes) it always 404.
The folder META-INF with context.xml is needed.
If you want to create a .war file you can deploy to a Tomcat instance using the Manager app, create a folder, put all your files in that folder (including an index.html file) move your terminal window into that folder, and execute the following command:
zip -r <AppName>.war *
I've tested it with Tomcat 8 on the Mac, but it should work anywhere
(Answers are pretty old, so here's what worked for me on Ubuntu 20.04 Tomcat9)
As root
cd /var/lib/tomcat9/webapps
mkdir -p myapp
cd myapp
cat >>index.html
<html><body>MY SIMPLE PAGE </body></html>
control-D # Press CONTROL+D to exit 'cat', create the file 'index.html'
systemctl restart tomcat9
In browser, use URL: http://127.0.0.1/myapp
(Of course, you can make page fancier, add CSS, etc., etc.)
I struggled a bit with older version of Apache Tomcat (7.0.68) running on Windows Server 2012, but this worked for me after a little bit of experimenting:
Create app folder with your static files (HTML, JS, CSS, assets, etc.).
Inside the folder create META-INF folder and add empty MANIFEST.MF.
Optionally zip the app folder and change the extension to .war.
Upload your app to Tomcat's webapps folder, either as a .war or just folder with your files.
Turned out, that META-INF with empty MANIFEST.MF file is enough for Tomcat to serve the app. No need to add WEB-INF or anything else (at least for my version of Tomcat).
Folder structure:
MyApp (folder)
|--index.html
|--app.js
|--app.css
|--assets (folder)
|--logo.png
|--...
|--META-INF (folder)
|--MANIFEST.MF (empty file)