Polymer / prpl-server

⚠️Maintenance mode⚠️ An HTTP server for Node designed to serve PRPL apps in production.
Other
425 stars 29 forks source link

basePath in JS with AppLocalizeBehavior and iron-ajax #39

Closed NicolaiSchmid closed 6 years ago

NicolaiSchmid commented 7 years ago

Hey, I'm trying to setup a dynamic server, which serves 4 different builds generated from the polymer-cli.

I'm using the basePath option in the config for correctly importing all HTML Imports, but when I try to load my locales.json file for i18n and AppLocalizeBehavior I get an error because the base tag is not respected by JS. Same goes with iron-ajax elements, which make requests in JS with XHR. Do you have any ideas, how I could solve this problem, preferably without rewriting all paths in my application? Thank You!

my polymer.json builds array:

"builds": [{
    "name": "none",
    "basePath": true,
    "browserCapabilities": [],
    "addServiceWorker": true,
    "bundle": true,
    "swPrecacheConfig": "sw-precache-config.js",
    "insertPrefetchLinks": true,
    "js": {
      "minify": true,
      "compile": true
    },
    "css": {"minify": true},
    "html": {"minify": true}
  },
  {
    "name": "noes6",
    "basePath": true,
    "browserCapabilities": ["push", "serviceworker"],
    "addServiceWorker": true,
    "addPushManifest": true,
    "swPrecacheConfig": "sw-precache-config.js",
    "insertPrefetchLinks": true,
    "js": {
      "minify": true,
      "compile": true
    },
    "css": {"minify": true},
    "html": {"minify": true}
  },
  {
    "name": "nopush",
    "basePath": true,
    "browserCapabilities": ["es2015", "serviceworker"],
    "addServiceWorker": true,
    "swPrecacheConfig": "sw-precache-config.js",
    "insertPrefetchLinks": true,
    "bundle": true,
    "js": {"minify": true},
    "css": {"minify": true},
    "html": {"minify": true}
  },
  {
    "name": "all",
    "basePath": true,
    "browserCapabilities": ["es2015", "push", "serviceworker"],
    "addServiceWorker": true,
    "addPushManifest": true,
    "swPrecacheConfig": "sw-precache-config.js",
    "js": {"minify": true},
    "css": {"minify": true},
    "html": {"minify": true}
  }]
DavidHenri008 commented 6 years ago

I also experience the same issue. Any suggestions?

NicolaiSchmid commented 6 years ago

Actually I have. I'm still using the same polymer.json build configuration from above, in my index.html I set the base tag: <base href="/"> (the newer versions of Polymer-starter-kit do this as well). All of the HTML imports are relative to the project root. In index.html like this:

<script src="bower_components/webcomponentsjs/webcomponents-loader.js" async></script>

In src/my-app.html:

<link rel="import" href="../bower_components/polymer/polymer-element.html">

You get the point... And for the express server, I use this code:

const prpl = require('prpl-server');
const express = require('express');
const config = require('./build/polymer.json');

const app = express();

app.get('/*', prpl.makeHandler('./build/', config));

app.listen(process.env.PORT || 80);