Keystone: Problem with upload images in Heroku

Created on 17 Jan 2020  路  5Comments  路  Source: keystonejs/keystone

Bug report

I'm having trouble uploading images using Cloudinary Adapter in Production (Heroku)

To Reproduce

Steps to reproduce the behaviour. Please provide code snippets or a repository:

  1. Set secureCookies: false
  2. Set app.set("trust proxy", 1);
  3. Deploy to Heroku
  4. Try upload image
  5. In console show this error

[Network error]: ServerParseError: JSON.parse: unexpected character at line 1 column 1 of the JSON data TypeError: e is undefined

In remote console

2020-01-17T14:03:17.474496+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=POST path="/admin/api" host=jumpittlabs-site-cms.herokuapp.com request_id=14e94647-88b8-43ef-9329-1aa1de849451 fwd="152.231.93.178" dyno=web.1 connect=1ms service=345ms status=503 bytes=0 protocol=https

Expected behaviour

I want upload image as it does in development

System information

  • OS: Heroku?
  • Firefox, Safari and Chrome

Screenshot

https://i.imgur.com/AyKyP7z.png

Aditional information

This is my index.js

require("dotenv").config();
const { Keystone } = require("@keystonejs/keystone");
const { PasswordAuthStrategy } = require("@keystonejs/auth-password");
const { GraphQLApp } = require("@keystonejs/app-graphql");
const { AdminUIApp } = require("@keystonejs/app-admin-ui");
const { MongooseAdapter: Adapter } = require("@keystonejs/adapter-mongoose");
const expressSession = require('express-session');
const MongoStoreMaker = require("connect-mongo");
const User = require("./models/User");
const Member = require("./models/Member");
const Project = require("./models/Project");
const Department = require("./models/Department");
const bodyParser = require("body-parser");
const { makeANiceEmail, transport } = require("./src/mail");
const MongoStore = MongoStoreMaker(expressSession);
const { ExpressApp } = require("@keystonejs-contrib/app-express");

const keystone = new Keystone({
  name: "jumpittlabs-site-cms",
  adapter: new Adapter(),
  sessionStore: new MongoStore({
    url: process.env.DATABASE_URL
  }),
  secureCookies: false
});

keystone.createList("User", User);
keystone.createList("Member", Member);
keystone.createList("Project", Project);
keystone.createList("Department", Department);

const authStrategy = keystone.createAuthStrategy({
  type: PasswordAuthStrategy,
  list: "User"
});

module.exports = {
  keystone,
  apps: [
    new GraphQLApp(),
    new AdminUIApp({ authStrategy }),
    new ExpressApp(app => {
      app.use(bodyParser.urlencoded({ extended: true }));
      app.use(bodyParser.json());
      app.post("/email", async function (req, res) {
        await transport.sendMail({
          from: "'Mr. Fox 馃' <[email protected]>",
          to: "[email protected]",
          subject: "Hello World",
          text: "Hello World?",
          html: makeANiceEmail
        }, (error, info) => {
          if (error) {
            return console.log(error);
          }
          console.log("Message sent: %s", info.messageId);
          res.sendStatus(200);
        });
      });
    })
  ],
  configureExpress: app => {
    if (process.env.NODE_ENV !== "development") {
      app.set("trust proxy", 1);
    }
  }
};

All 5 comments

Did you solve this? About to start testing heroku

Nope. I don鈥檛 know yet.

@alvaaz is there anything in the Heroku logs from the app itself? There should be some around the same time tagged as app[web.1] or similar.

I _suspect_ this is actually the same problem described in #2101.

Yep. I fix it for now, setting node version to 12.13.x in Heroku.

This fixed a similar issue for me. The error in the logs was the following:
EDIT: (This only happened while uploading images)

"name":"graphql"
"message": "Maximum call stack size exceeded"
...
"name":"GraphQLError"
"errors":[
      {
        "name":"RangeError",
        "message":"Maximum call stack size exceeded",
        "stack": "ReadStream.open (node_modules/fs-capacitor/lib/index.js:90:11)"
      }
],

fixed by updating the engines on the package.json

{
  "engines": {
    "node": "12.16.x"
  }
}

thanks @alvaaz

Was this page helpful?
0 / 5 - 0 ratings

Related issues

justinmoon picture justinmoon  路  13Comments

ra-external picture ra-external  路  12Comments

molomby picture molomby  路  11Comments

wesbos picture wesbos  路  16Comments

bpavot picture bpavot  路  11Comments