0

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.

curt
  • 4,422
  • 3
  • 42
  • 61

1 Answers1

1

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.

  • ... and either you switch to `HashLocationStrategy` or ensure the server supports HTML5 pushstate http://krasimirtsonev.com/blog/article/apache-htaccess-for-html5-push-state-manipulations. See also http://stackoverflow.com/questions/36861628/location-and-hashlocationstrategy-stopped-working-in-beta-16 – Günter Zöchbauer Jul 05 '16 at 08:23
  • Now that I think about it, that makes sense. – curt Jul 05 '16 at 16:51
  • @GünterZöchbauer, does HashLocationStrategy work with pub serve? I also can't reload pages and have read several questions and answers regarding the problem, but they don't mention under which environment they are implementing the fix. I don't want to waste time trying something that isn't meant to work with pub serve. – curt Jul 05 '16 at 16:59
  • `pub serve` only supports `HashLocationStrategy`. AdaoJunior built a simple tool that allows to use `pub serve` to be used with `PathLocationStrategy` https://pub.dartlang.org/packages/pub_serve_rewrites. Also for example when `nginx` is used as proxy that forwards to `pub serve` you can configure `nginx` to make `pub serve` make with `PathLocationStrategy` (I don't know nginx myself, it's just an example) – Günter Zöchbauer Jul 05 '16 at 17:06