Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
10
rated 0 times [  16] [ 6]  / answers: 1 / hits: 28305  / 10 Years ago, thu, july 3, 2014, 12:00:00

I am trying to use gulp-connect to forward all requests to api/ to localhost:3000. I found an example at https://github.com/AveVlad/gulp-connect/issues/27



and setup my connect task like this:



gulp.task('connect', function(){
connect.server({
root: './app',
middleware: function(connect, o) {
return [ (function() {
var url = require('url');
var proxy = require('proxy-middleware');
var options = url.parse('http://localhost:3000/api');
options.route = 'api';
return proxy(options);
})()]
}
});
});


Running this task warns that connect deprecated connect(middleware): use app.use(middleware) instead node_modules/gulp-connect/index.js:39:19 and this task does not forward requests as expected.



I looked at the connect source to see if I could work around the depreciation, but it is beyond my level in js:



 ConnectApp.prototype.server = function() {
var app, middleware;
middleware = this.middleware();
app = connect.apply(null, middleware);
server = http.createServer(app);
app.use(connect.directory(typeof opt.root === object ? opt.root[0] : opt.root));
server.listen(opt.port);
this.log(Server started http:// + opt.host + : + opt.port);
if (opt.livereload) {
tiny_lr.Server.prototype.error = function() {};
lr = tiny_lr();
lr.listen(opt.livereload.port);
return this.log(LiveReload started on port + opt.livereload.port);
}
};


I cannot figure out how to change my gulp-file to use app.use(middleware), the app variable is not exported by the connect module.


More From » gulp

 Answers
82

This is a reported issue that should be fixed in the next gulp-connect release on NPM :



https://github.com/AveVlad/gulp-connect/commit/9bd7da765d6763bbee566cc5fc03b873ccf93e37
https://github.com/AveVlad/gulp-connect/issues/67


[#70337] Tuesday, July 1, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ryderalfonsos

Total Points: 655
Total Questions: 88
Total Answers: 91

Location: Nauru
Member since Thu, Feb 2, 2023
1 Year ago
ryderalfonsos questions
Mon, Sep 9, 19, 00:00, 5 Years ago
Wed, Feb 13, 19, 00:00, 5 Years ago
Tue, Feb 12, 19, 00:00, 5 Years ago
Fri, Dec 28, 18, 00:00, 6 Years ago
;