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

Error: "Cannot switch to old mode now." #25

Closed
Siyfion opened this issue May 21, 2014 · 8 comments
Closed

Error: "Cannot switch to old mode now." #25

Siyfion opened this issue May 21, 2014 · 8 comments

Comments

@Siyfion
Copy link

Siyfion commented May 21, 2014

I'm using node.js version v0.10.28, ExpressJS v4.3.0 and Multer v0.0.7

When I send any files to a route which accepts multipart form data I get the error above. It was working perfectly fine, I'm not sure what's changed. 😕

@hacksparrow
Copy link
Member

Multer 0.1.0 just released with busboy 0.2.6. Can you check with it?

@Siyfion
Copy link
Author

Siyfion commented May 30, 2014

Nope, I've updated to v0.1.0 and I still get the same issue. Also updated to the latest express v4.3.2, etc.

@hacksparrow
Copy link
Member

Can you paste the stack trace? I am suspecting something in Busboy.

@Siyfion
Copy link
Author

Siyfion commented May 30, 2014

Sounds stupid, but there is no stack trace, I just get the error in my ExpressJS error handler with the error object:

error: [Error: Cannot switch to old mode now.]
error: An error occured when user sent the following request:
 URL:   POST http://localhost/static/images
 query: {}
 body:  {}

 Error: [Error: Cannot switch to old mode now.]

@Siyfion
Copy link
Author

Siyfion commented Jun 3, 2014

Sorry @hacksparrow but I think I'm going to have to switch to using formidable for the time being as I cannot get this working at all... I'm really not sure what the hell happened though, it was working. Could it be due to the fact that I'm also using the Socket.IO library?

@Siyfion
Copy link
Author

Siyfion commented Jun 3, 2014

Just to add to my last comment, I don't believe it's Socket.IO related, I stripped it out of my project entirely and the issue still persisted. Here's a full list of my dependencies, in case it might help in some way or other:

"dependencies": {
    "async": "~0.9.0",
    "aws-sdk": "~2.0.0-rc.19",
    "body-parser": "^1.3.0",
    "compression": "^1.0.3",
    "cors": "~2.3.1",
    "express": "~4.4.1",
    "gm": "~1.16.0",
    "hiredis": "^0.1.17",
    "lodash": "~2.4.1",
    "mongoose": "~3.8.12",
    "morgan": "^1.1.1",
    "multer": "0.1.0",
    "nodemailer": "~0.6.5",
    "passport": "^0.2.0",
    "passport-http": "^0.2.2",
    "password-hash": "^1.2.2",
    "redis": "^0.10.3",
    "socket.io": "^1.0.4",
    "twit": "~1.1.15",
    "validator": "~3.13.0",
    "winston": "~0.7.3",
    "winston-loggly": "^1.0.1"
  },
'use strict'

# Module dependencies.
express = require 'express'
http = require 'http'
sockets = require 'socket.io'
bodyParser = require 'body-parser'
multer  = require 'multer'
morgan  = require 'morgan'
compress = require 'compression'
cors = require 'cors'
passport = require 'passport'
winston = require 'winston'
error = require './middleware/errorHandling'

module.exports = () ->

  app = express()
  server = http.createServer(app)
  io = sockets.listen(server)

  app.set 'port', process.env.PORT or 3000

  winstonStream =
    write: (message, encoding) ->
      winston.info message

  app.use morgan stream: winstonStream
  app.use compress()
  app.use bodyParser()
  app.use multer()
  app.use cors()

    # origin: true
    # methods: ['GET', 'PUT', 'POST', 'DELETE']
    # credentials: true
    # maxAge: 3600

  # Add the passport authentication middleware
  app.use passport.initialize()

  # Ensure that all routes are authenticated, except the route
  # that gets the user count for a given site
  authentication = passport.authenticate 'basic', session: false
  app.use (req, res, next) ->
    if (req.url.indexOf('/sites/') is 0 and
      req.url.indexOf('/userCount', req.url.length - '/userCount'.length) isnt -1) or
      req.url.indexOf('/twitter/userTimeline') is 0
        next()
      else
        authentication(req, res, next)

  # Configure the routes
  require('./routes.js')(app)

  # Configure the web socket listeners
  require('./web_sockets')(io)

  app.use error.handle404
  app.use error.logErrors
  app.use error.apiErrors

  winston.info "Express server listening on port: #{app.get('port')}"
  server.listen app.get('port')

@Siyfion Siyfion closed this as completed Jun 3, 2014
@Siyfion Siyfion reopened this Jun 3, 2014
@Siyfion
Copy link
Author

Siyfion commented Jun 4, 2014

@hacksparrow BINGO! I've figured it out...

It seems to be related to my cors library.

Changing:

  app.use morgan stream: winstonStream
  app.use compress()
  app.use bodyParser()
  app.use multer()
  app.use cors()

to:

  app.use morgan stream: winstonStream
  app.use cors()
  app.use compress()
  app.use bodyParser()
  app.use multer()

(note the ordering!) fixes the issue.

@Siyfion Siyfion closed this as completed Jun 4, 2014
@hacksparrow
Copy link
Member

Glad you got it working!

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

No branches or pull requests

3 participants