Running AngularDart on Apache - apache

My Angular Dart site runs fine with pub serve. I would prefer to run it with Apache. When I enter the url jazzcat.loc/index.html I get the following browser errors:
GET http://jazzcat.loc/packages/browser/dart.js index.html:22
GET http://jazzcat.loc/packages/polymer/polymer.dart package:polymer/polymer.dart:1
An error occurred loading file: package:polymer/polymer.dart index.html:22
GET http://jazzcat.loc/packages/angular2/platform/browser.dart package:angular2/platform/browser.dart:1
An error occurred loading file: package:angular2/platform/browser.dart
index.html:22 GET http://jazzcat.loc/packages/jazzcat/app_component.dart package:jazzcat/app_component.dart:1
An error occurred loading file: package:jazzcat/app_component.dart favicon.ico:1
GET http://jazzcat.loc/favicon.ico 404 (Not Found)
The virtual host entry for the site is:
<VirtualHost *:80>
ServerName jazzcat.loc
DocumentRoot /Volumes/Data/htdocs/jazzcat/web
<directory /Volumes/Data/htdocs/jazzcat/web>
Allow from all
Options -MultiViews
Require all granted
</directory>
</VirtualHost>
There is no .htaccess file
This is index.html:
<!DOCTYPE html>
<html>
<head>
<title>Jazz Cat</title>
<script>
window.Polymer = window.Polymer || {};
window.Polymer.dom = 'shadow';
</script>
<!-- For testing using pub serve directly use: -->
<base href="/">
<!-- For testing in WebStorm use: -->
<!-- base href="/dart/web/" -->
<link href="master.css" rel="stylesheet" type="text/css" />
<script defer src="main.dart" type="application/dart"></script>
<script defer src="packages/browser/dart.js"></script>
</head>
<my-app>Loading...</my-app>
</html>
I also tried using
<base href="/dart/web/">
It also errors out. I'm testing in the Chromium browser.
I've seen questions and answers here about routing. They seem to apply to routing beyond index.html.

AFAIK pub serve is meant to be used during development, if you want to use apache to serve your app, you might need to use pub build to transform (and optimize) your app to a regular html+javascript app, here you might find more information.

Related

https redirect with Apache is returning a blank page

I have a WAMP installation running on a Raspberry pi 3. Apache v2.4.33, php 7.2.4.
I want the default url address of my site - "//www.quintic.co.uk/" - to actually address "//www.quintic.co.uk/index.php?home". So I added the following to the .htaccess file:
DirectoryIndex index.php?home
I have also configured Apache to always use https protocol, by updating the apache config file with the following:
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{SERVER_NAME}/$1 [END,NE,R=permanent]
For the most part, all the above seems to be working perfectly. For example, if I request http://www.quintic.co.uk/ then I am redirected to https://www.quintic.co.uk/index.php?home.
All http requests are switched correctly to https requests.
All https requests are returning correctly, with the exception of https://www.quintic.co.uk/, which returns a blank page.
The actual instruction set returned from a https://www.quintic.co.uk/ request is as follows:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-eqiv="refresh" content="0" url="https://www.quintic.co.uk/index.php?home" />
<script type="text/javascript" src="https://ff.kis.v2.scr.kaspersky-labs.com/E989763D-7B5C-014A-B514-22905C3EEE53/main.js" charset="UTF-8"></script></head>
<body>
</body>
<!-- End of #container-->
<!--Scripts after page loads-->
</html>
If I cut & paste the url in the meta statement into a browser, the home page is returned fine.
Can anyone shed some light on why the default url redirect is not working with https.
Thanks
SteveD430
The problem was in the apache2.conf. Within the Quintic site 'Directory' element. I had the following:
AllowOverride None
Order allow,deny
allow from all
Require all granted
It needed to be
AllowOverride All
Site is now working perfectly.

I'm having really difficult time with my .htaccess file

I'm having really difficult time with my .htaccess file
(Apache) httpd.conf: The following are uncommented:
mod_rewrite
LoadModule rewrite_module modules/mod_rewrite.so
My document root / directory:
DocumentRoot "f:/www"
<Directory "f:/www">
My index.html file is in:
F:\www\portfolio2
My .htaccess file is in:
F:\www\portfolio2
Inside my .htaccess file:
RewriteEngine on
RewriteRule ^portf/([0-9a-zA-Z]+) index.html?p=$1 [NC,L]
The directory:
F:\www\portfolio2\portf
does not exist, but I'm pretty sure it doesn't need to, right?
Inside my index.html :
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="css/portfolio.css" rel="stylesheet">
<script src="jquery/jquery-3.2.1.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="js/javascript.js"></script>
When I test the url:
http://localhost/portfolio2/portf/qweasd
My console logs the following errors / warnings:
Uncaught SyntaxError: Unexpected token < jquery-3.2.1.min.js:1
Uncaught SyntaxError: Unexpected token < bootstrap.min.js:1
Uncaught SyntaxError: Unexpected token < javascript.js:1
Resource interpreted as Stylesheet but transferred with MIME type text/html:
"http://localhost/portfolio2/portf/bootstrap/css/bootstrap.min.css".
qweasd:20
Resource interpreted as Stylesheet but transferred with MIME type text/html:
"http://localhost/portfolio2/portf/css/portfolio.css".
qweasd:21
From What I see, it thinks I have a directory named "portf", which I don't.
Am I doing something wrong?
EDIT: I forgot to mention, the page loads but not the CSS, JavaScript, etc.
EDIT2: Solved. I added: RewriteBase /portfolio2/ to .htaccess and I'm using relative URL's throughout my site. I also replaced rel="stylesheet" and the styles are now being applied. Then I added <base href="/portfolio2/">
in <head> before CSS and JavaScript imports. Cheers!

Issues with httpd DocumentRoot inside of Vagrant sync folder

I've set up a Vagrant LAMP development environment on my Windows 8.1 machine. The guest operating system is Centos 7. I have a subfolder of my main vagrant folder called workspace which I have synced to /var/www/workspace on my guest. I also have port 80 being forwarded to the guest and httpd running with DocumentRoot of /var/www/workspace. When the folder is empty, I get the standard apache test page. Everything is good so far.
I created an index.html file in the workspace folder on my host machine in SublimeText with the following contents.
<html>
Test1
</html>
I checked this in the web browser on my host, and get the expected result
Test1
I continued to edit the index.html file, adding head and body tags and some divs:
<html>
<head>
<title>Test site</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div class="button">Test1</div>
<div class="button">Test2</div>
</body>
</html>
Then I change the text in the links and add a third div.
<html>
<head>
<title>Test site</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div class="button">Blog</div>
<div class="button">Resume</div>
<div class="button">Experiments</div>
</body>
</html>
As soon as I add the third div, my browser starts returning a previous version of the file with Test1 and Test2 as the link text. I made sure my browser cache was disabled. I checked in the Network section of the Chrome dev console to make sure that the file was coming from the webserver, which it was. I check in vi on the guest machine, and the index file contains the Blog, Resume, Experiments links. If I modify the file in vi by just adding a new line or anything, it fixes the issue. If I remove the third div, it fixes the issue. If I remove the css reference line, it fixes the issue. I have no idea where this old version is or why it's being returned when certain changes are made. My assumption is that it is a vagrant syncing issue, but I'm open to any ideas on what else might be going wrong.
I've found an answer to my problem although not an ideal one. It appears this is an issue with VirtualBox, not Vagrant. More information about this issue can be found here:
Ticket 9069
Ticket 819
There is no solution, but there is a proposed workaround to avoid this issue. The workaround is to add this to your httpd.conf:
EnableSendfile off
EnableMMAP Off

Redict Apache Directory Index

I've got an Apache server, and I'd like to set it up such that when a directory is requested that does not have an index.html file (and thus, Apache would, by default, generate a directory listing), Apache instead redirects (ideally using HTTP code 303) to a given url.
Unless absolutely necessary, I'd like to stay away from going outside Apache (for example, by having Apache load a php script which writes the headers manually). This is an otherwise static site, and I'd like to avoid having to introduce scripting languages into the mix.
Also, note that this post doesn't solve my problem since all of the proposed solutions use external scripts.
So I figured out that by using a combination of HTML meta refreshing and JavaScript redirection, I could cover almost all browsers in use and still have a static file. So what I did was this. In the apache site config, I put a directive that told apache to first look for index.html files, and if that failed, use a site-wide /no-index.html:
<Directory /path/to/web/root>
DirectoryIndex index.html /no-index.html
</Directory>
no-index.html, then, contained the following:
<html>
<head>
<meta http-equiv="refresh" content="0; url=/">
<script type="text/javascript">
window.location = "/";
</script>
</head>
</html>
(in this example it redirects to the web root, /, but you could replace that with whatever url you wanted)
See here for an explanation of what the <meta> tag is doing.

Favicon for all the pages in my website

I've learned that the way to add favicon for a web page is to have the following lines in the page.
<link rel="SHORTCUT ICON" type="image/x-icon" href="http://mysite.com/faviconfilename.ico"/>
<link rel="icon" type="image/x-icon" href="http://mysite.com/faviconfilename.ico" />
Should i add this code in each and every page my site has?? I use Apache - tomcat clustering to serve pages. Is there any other easy way to do this?
It is usually enough to place a file called "favicon.ico" in the root of your website.
You can get rid of the unnecessary processing and traffic as well as the error log entries by using the following Apache configuration incantations:
# Don't bother looking for favicon.ico
Redirect 404 /favicon.ico
# Send custom text instead of sending the custom error page
<Location /favicon.ico>
ErrorDocument 404 "No favicon"
</Location>
Modify the apache config.
upload this file to the root directory of your website. Make sure that it is readable so that apache can read it. If you have shell access, type: "chmod +r favicon.ico".
Then edit httpd.conf and insert the following line:
"AddType image/x-icon .ico"
Your approach works when you don't have access to your apache config. In this case, if you are using any framework then you should add it to your layout/template.
Here is my method for php sites. It ensures that if you update the favicon, it will be updated immediatly when your clients visit your site:
<link rel="shortcut icon" href="favicon.ico?v=<?php echo time() ?>" />