首页 > 解决方案 > 如何在 grunt-cli 中提供外部端口,以便在服务器上托管它?

问题描述

我正在使用 docker 制作图像来运行我的前端。

它在我的笔记本电脑上运行良好,但在我的服务器上,我无法通过浏览器访问它。

您可以查看我的屏幕截图以了解我的浏览器对此有何评论。

所以,我的项目在 Angular (grunt-cli) 前端,后端在烧瓶中,数据库是 mongodb。后端工作正常,但 grunt-cli,我无法通过浏览器访问它,但我可以 curl http://:9000 来查看内容。

这是我的 Gruntfile.js——

module.exports = function(grunt) {

// ===========================================================================
// CONFIGURE GRUNT ===========================================================
// ===========================================================================
grunt.initConfig({

  // get the configuration info from package.json ----------------------------
  // this way we can use things like name and version (pkg.name)
  pkg: grunt.file.readJSON('package.json'),

  // configure jshint to validate js files -----------------------------------
  jshint: {
    options: {
      reporter: require('jshint-stylish')
    },
    all: ['Grunfile.js', 'src/components/**/*.js']
  },

  // configure uglify to minify js files -------------------------------------
  uglify: {
    options: {
      banner: '/*\n <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> \n*/\n'
    },
    build: {
      files: {
        'dist/js/components.min.js': 'src/components/**/*.js'
      }
    }
  },

  // compile less stylesheets to css -----------------------------------------
  less: {
    build: {
      files: {
        'dist/css/pretty.css': 'src/css/pretty.less'
      }
    }
  },

  // configure cssmin to minify css files ------------------------------------
  cssmin: {
    options: {
      banner: '/*\n <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> \n*/\n'
    },
    build: {
      files: {
        'dist/css/style.min.css': 'src/css/style.css'
      }
    }
  },

  // configure watch to auto update ------------------------------------------
  watch: {
    stylesheets: {
      files: ['src/**/*.css', 'src/**/*.less'],
      tasks: ['less', 'cssmin']
    },
    scripts: {
      files: 'src/**/*.js',
      tasks: ['jshint', 'uglify']
    }
  },
express:{
  all:{
    options:{
      port:9000,
      hostname:'0.0.0.0',
      bases:['./src'],
      livereload: true
    }
  }
}

});

// ===========================================================================
// LOAD GRUNT PLUGINS ========================================================
// ===========================================================================
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-express');

// ===========================================================================
// CREATE TASKS ==============================================================
// ===========================================================================

grunt.registerTask('serve-waalos', ['jshint','cssmin','uglify','express','watch']);
grunt.registerTask('default', ['test', 'build']);

 };

标签: javascriptangulardockergruntjsdevops

解决方案


推荐阅读