0

I am trying to upgrade my old Polymer application to Polymer v3. Nearly Everything works fine if I use polymer serve.

But I have to also use some php files to connect to the backend and there is the problem.

When I try to run the application using polymer serve, PHP files are not found and returning 404 whenever I try to make a POST request on them.

Non working example. Having the following file structure:

|_ phpFile.php
|
|_ jsFile.js

Inside jsFile.js

fetch("phpFile.php", {
        method: 'POST',
        headers: new Headers({
            Accept: 'application/json',
            'Content-Type': 'application/json'
        },
        body: JSON.stringify({
            testData: true
        })
    }).then(response => {
        console.warn(response);
    });

When I try to run the application with XAMPP (virtual host), Making a POST request returns exactly what I need, which is great. But import like this:

import {PolymerElement, html} from '@polymer/polymer/polymer-element.js';

stop working, because there is no bundler that would replace @ with the current path. And no, I can't simply rewrite it to '/node_modules/@polymer/polymer/polymer-element.js'. All of the polymer elements are using this notation. I would have to rewrite all source codes which is nonsense.

I need to either make successfull POST on php files while serving with polymer serve or replace all @ inside imports while serving with localhost (XAMPP or any other service)

Is there anyone who succesfully implemented connection to php file in Polymer 3? Or anyone who knows some workaround, solution for this?

Kuba Šimonovský
  • 2,013
  • 2
  • 17
  • 35

1 Answers1

0

If You are using PHP for APIs then create separate Application and run it on xampp.

In sort create tow different Application. One for back end (PHP app) and another for front end (Polymer app).

  • that's a nice idea. But imagine how it would work when I build it and place it on live server. And, maybe I wasn't clear, but i have those PHP files just only as middleware. I have 3 php files which are used to make a connection to the API. – Kuba Šimonovský Sep 22 '18 at 11:29
  • It'll work in server. You can run both Application on server. It'll work same as working in your local. – Vipul Solanki Sep 24 '18 at 07:04