【问题标题】:How to change gulp port according to specific path如何根据特定路径更改 gulp 端口
【发布时间】:2016-03-17 11:27:43
【问题描述】:

我是 gulp 的新手,我正在为我的应用程序使用 gelp 服务器,我在端口 8080 上有一个 java 服务器,我想在另一个项目中使用 oAuth2 进行身份验证,我使用 grunt 以及我如何将用户重定向到 oAuth2

这里是我的 gruntfile 代码

connect: {
  options: {
    port: 9000,
    // Change this to '0.0.0.0' to access the server from outside.
    hostname: 'localhost',
    livereload: 35729
  }, proxies: [
    {
      context: [
        '/_ah',
        '/secured',
        '/oauth2login',
        '/oauth2callback'
      ],
      host: 'localhost',
      port: 8080,
      https: false,
      changeOrigin: false,
      xforward: false
    }
  ]
}

现在我想在我的 gulpfile.js 代码中对 gulp 做同样的事情

var options = {
    port: 3000,
    ghostMode: {
        clicks: false,
        location: false,
        forms: false,
        scroll: true
    },
    injectChanges: true,
    logFileChanges: true,
    logLevel: 'debug',
    logPrefix: 'gulp-patterns',
    notify: true,
    reloadDelay: 0, //1000,
    online: false,
    proxies: [
    {
      context: [
        '/_ah',
        '/secured',
        '/oauth2login',
        '/oauth2callback'
      ],
      host: 'localhost',
      port: 8080,
      https: false,
      changeOrigin: false,
      xforward: false
    }
  ]
};

我添加了代理但没有工作我想这样做,因为在我的 app.run 中我想使用 oAuth2 验证用户

这里是我的 app.run

app.run(function($rootScope, datastoreUser){

  datastoreUser.LoginUser("me").then(function(result){

    console.log("User is authenticated");
    console.log(result);

  },function(error){
    console.log("An error occured user is not authenticated");
    console.log(error);
    window.location.href = '/oauth2login';
  })
})

【问题讨论】:

    标签: java angularjs gruntjs gulp


    【解决方案1】:

    如果其他人需要,我找到了解决问题的方法

    我在这里添加了 http-proxy-middleware 模块的代码

    var proxyMiddleware = require('http-proxy-middleware');
    var options = {
        port: 3000,
        ghostMode: {
            clicks: false,
            location: false,
            forms: false,
            scroll: true
        },
        injectChanges: true,
        logFileChanges: true,
        logLevel: 'debug',
        logPrefix: 'gulp-patterns',
        notify: true,
        reloadDelay: 0, //1000,
        online: false
    };
    function serveApp() {
        gulp.watch([config.sass], ['sass']);
    
        options.server = {
            baseDir: [
                config.client,
                config.tmp
            ]
        };
        options.files = [
            config.client + '/**/*.*',
            '!' + config.sass,
            config.tmp + '/**/*.css'
        ];
    
        options.middleware = proxyMiddleware([
            '/_ah',
            '/secured',
            '/oauth2login',
            '/oauth2callback'
          ],
        {
          target: 'http://localhost:8080'
        });
    
        browserSync(options);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-29
      • 2021-10-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多