0

I have upgraded my project from sails v0.9.8 to sails v0.11. When do i try to retrive data, it gives this error.

Error: Can't set headers after they are sent. at ServerResponse.OutgoingMessage.setHeader (http.js:690:11) at ServerResponse.appendHeader (/usr/lib/node_modules/sails/node_modules/express/node_modules/connect/lib/patch.js:94:33) at ServerResponse.res.setHeader (/usr/lib/node_modules/sails/node_modules/express/node_modules/connect/lib/patch.js:125:19) at ServerResponse.res.set.res.header (/home/abc/xyz/git/propgod-internal-V0.11/clients/web/node_modules/sails/node_modules/express/lib/response.js:577:10) at ServerResponse.res.cookie (/home/abc/xyz/git/propgod-internal-V0.11/clients/web/node_modules/sails/node_modules/express/lib/response.js:650:8) at Request.callback [as _callback] (/home/abc/xyz/git/propgod-internal-V0.11/clients/web/api/services/DataService.js:51:34) at Request.self.callback (/home/abc/xyz/git/propgod-internal-V0.11/clients/web/node_modules/request/request.js:123:22) at Request.emit (events.js:98:17) at Request. (/home/abc/xyz/git/propgod-internal-V0.11/clients/web/node_modules/request/request.js:1047:14) at Request.emit (events.js:117:20) at IncomingMessage. (/home/abc/xyz/git/propgod-internal-V0.11/clients/web/node_modules/request/request.js:998:12) at IncomingMessage.emit (events.js:117:20) at _stream_readable.js:944:16 at process._tickDomainCallback (node.js:486:13)

.

How can i enable cors for my application?

Note : I'm loading scripts and styles using Gruntfile.js. I have separate modules for client and server side.

Please help me out !!!

Meeker
  • 5,979
  • 2
  • 20
  • 38
DebuggerCoder
  • 236
  • 4
  • 15

1 Answers1

1

CORS is configured via config/cors.js but can be changed on a per route basis

http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.cors.html

Depending on what your doing there are many reasons why you might getting the error message your asking about.

setheader gives error: "throw new Error('Can\'t set headers after they are sent.');"

Sails.js Can't set headers after they are sent

sailsjs policy causing Can't set headers after they are sent error

Community
  • 1
  • 1
Meeker
  • 5,979
  • 2
  • 20
  • 38
  • As i mentioned that i have two modules api and client. so when do i make a call to api controller from client module the response is coming but at the same time error occurs (ie. i have asked). Its looking like the grunt file is not loading header files after response coming from api to client or sails is not able to make a CORS call between api or client or may be socket calling issue as in new sails version they have deprecated the methods as beforeConnect() and afterDisconnect() . – DebuggerCoder Mar 05 '15 at 04:04