uSked / mosaico-php-backend

A PHP backend for Mosaico
GNU General Public License v3.0
32 stars 34 forks source link

Problem with php-backend and nginx #19

Open NkDimi opened 7 years ago

NkDimi commented 7 years ago

I am using template-versafix-1 Operation system: Amazon Linux AMI 2016.03.3 (HVM), SSD Volume Type Version: ImageMagick 6.7.8-9 2016-06-22 Q16 http://www.imagemagick.org npm -v 3.9.6 node -v v5.9.1 background grunt

npm list --depth=0
mosaico@0.14.0
├── aliasify@1.9.0
├── async@0.9.0
├── autoprefixer-core@5.2.1
├── body-parser@1.13.3
├── bower@1.4.1
├── bower-npm-install@0.5.10
├── browserify@11.0.1
├── browserify-shim@3.8.10
├── cheerio@0.19.0
├── csswring@3.0.7
├── deamdify@0.1.1
├── debowerify@1.2.0
├── express@4.14.0
├── gm@1.18.1
├── grunt@0.4.5
├── grunt-bowercopy@1.2.0
├── grunt-browserify@4.0.0
├── grunt-contrib-connect@0.9.0
├── grunt-contrib-copy@0.8.2
├── grunt-contrib-jshint@0.11.2
├── grunt-contrib-less@1.0.1
├── grunt-contrib-watch@0.6.1
├── grunt-exorcise@2.0.0
├── grunt-express@1.4.0
├── grunt-jasmine-node-coverage@0.4.1
├── grunt-newer@1.1.1
├── grunt-postcss@0.6.0
├── jasmine-core@2.3.4
├── jasmine-node@1.14.5
├── jquery-file-upload-middleware@0.1.7
├── jshint-stylish@2.0.1
├── load-grunt-tasks@3.1.0
├── lodash@3.10.1
├── mockery@1.4.0
├── morgan@1.6.1
├── nodemailer@1.4.0
├── phantomjs@1.9.16
├── styliner@0.8.9
├── uglifyify@3.0.1
└── watchify@3.3.1

I am using your editor.html and this is a problem:

Unexpected upload error (SyntaxError: Unexpected token < in JSON at position 0)

screen shot 2016-07-13 at 14 07 27

Placeholder images are showing and also img are in uploads folder.

This is a nginx configuration:

location /dl/ {
        if (!-e $request_filename) {
          rewrite ^/(.*)$ /index.php break;
        }
    }

    location /img/ {
        if (!-e $request_filename) {
          rewrite ^/(.*)$ /index.php break;
        }
    }

    location /upload/ {
        if (!-e $request_filename) {
          rewrite ^/(.*)$ /index.php break;
        }
    }

This is how folder looks on server:


-rw-r--r--   1 nginx nginx     6896 Jul 13 11:08 Gruntfile.js
-rw-rw-r--   1 nginx nginx    35141 Nov  6  2015 LICENSE
-rw-rw-r--   1 nginx nginx     1723 Nov  6  2015 README.md
drwxr-xr-x   2 nginx nginx     4096 Jul 12 12:59 backend
-rw-r--r--   1 nginx nginx     2054 Jul  5 13:58 bower.json
drwxr-xr-x  26 nginx nginx     4096 Jul  5 14:04 bower_components
drwxr-xr-x   2 nginx nginx     4096 Jul 12 07:20 build
-rw-r--r--   1 nginx nginx      158 Jul 13 06:50 config.php
drwxr-xr-x   6 nginx nginx     4096 Jul  5 14:04 dist
drwxr-xr-x   2 nginx nginx     4096 Jul 12 14:55 dl
-rw-rw-r--   1 nginx nginx     2835 Jul 13 11:10 editor.html
-rw-r--r--   1 nginx nginx     2594 Jul 11 09:53 editor.html.bak
-rw-r--r--   1 nginx nginx     2036 Jul 11 10:13 editor.html.orig
-rw-r--r--   1 nginx nginx     1150 Jul  5 13:58 favicon.ico
-rw-r--r--   1 nginx nginx      737 Jul 13 11:59 grunt.log
-rw-r--r--   1 root  root         6 Jul 13 11:59 grunt.pid
drwxr-xr-x   2 nginx nginx     4096 Jul 12 14:54 img
-rw-r--r--   1 nginx nginx    13820 Jul  5 14:00 index.html
drwxr-xr-x 582 nginx nginx    20480 Jul 12 13:03 node_modules
-rw-r--r--   1 nginx nginx     2335 Jul  8 11:30 package.json
drwxrwxr-x   5 nginx nginx     4096 Jul 12 13:45 php-backend
-rw-r--r--   1 nginx nginx       66 Jul  8 10:11 phpinfo.php
drwxr-xr-x   5 nginx nginx     4096 Jul  5 13:58 res
-rw-r--r--   1 nginx nginx      449 Jul  5 13:58 server-config.js
drwxr-xr-x   3 nginx nginx     4096 Jul  5 13:58 spec
drwxr-xr-x   5 nginx nginx     4096 Jul  5 13:58 src
drwxr-xr-x   2 nginx nginx     4096 Jul  5 13:58 tasks
drwxr-xr-x   5 nginx nginx     4096 Jul  5 13:58 templates
drwxr-xr-x   2 nginx nginx     4096 Jul 12 14:55 upload
drwxr-xr-x   3 nginx nginx     4096 Jul 13 11:11 uploads

I also try when folders are in php-backend and also in mosaico folder.

I read all your suggestion from Issues but I can not find solution for this error. Also try to change path with adding or removing slash but still not working.

nabenzine commented 7 years ago

I got the same problem

NkDimi commented 7 years ago

i change editor.html in this

$(function() {
  if (!Mosaico.isCompatible()) {
    alert('Update your browser!');
    return;
  }
  var basePath = window.location.href.substr(0, window.location.href.lastIndexOf('/'));

  var plugins;
  plugins = [function(vm) {window.viewModel = vm; }];

  var ok = Mosaico.init({
    imgProcessorBackend: basePath+'/img',
    emailProcessorBackend: basePath+'/dl',
    titleToken: "Responsive Email Designer",
    fileuploadConfig: {
      url: basePath+'/upload',
      // messages??
    }
  }, plugins);
  if (!ok) {
    console.log("Missing initialization hash, redirecting to main entrypoint");
    document.location = ".";
  }
});

Now i do not have this error but he always give me first image from /upload folder this is a reason because srcMatch: null so he do not have right path to /uploads folder to make match. When I find solution I will post it.

markalston commented 7 years ago

While this project is seemingly dead I did find a solution to your loading of the first picture. While in config.php the paths SAY that they are relative to BASE_URL they are not. So if your url is /mosaico/editor.html... then the paths need /mosaico/ in front.