Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with upload images in Heroku #2256

Closed
alvaaz opened this issue Jan 17, 2020 · 5 comments
Closed

Problem with upload images in Heroku #2256

alvaaz opened this issue Jan 17, 2020 · 5 comments

Comments

@alvaaz
Copy link

alvaaz commented Jan 17, 2020

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);
    }
  }
};
@wesbos
Copy link
Contributor

wesbos commented Jan 23, 2020

Did you solve this? About to start testing heroku

@alvaaz
Copy link
Author

alvaaz commented Jan 24, 2020

Nope. I don’t know yet.

@molomby
Copy link
Member

molomby commented Feb 4, 2020

@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.

@alvaaz
Copy link
Author

alvaaz commented Feb 24, 2020

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

@jenriquejr
Copy link

jenriquejr commented Apr 20, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants