Grunt 服务器没有为我的应用程序使用虚拟主机名。vhost 和 httpd 已设置,但 grunt 没有使用它们

     2023-02-25     79

关键词:

【中文标题】Grunt 服务器没有为我的应用程序使用虚拟主机名。vhost 和 httpd 已设置,但 grunt 没有使用它们【英文标题】:Grunt server does not use virtual host name for my app..vhost and httpd are set up but grunt is not using them 【发布时间】:2013-11-22 01:55:59 【问题描述】:

所以我尝试使用名称而不是使用 127 0 0 1 来设置我的应用程序。 每次我运行 grunt 时,我的地址都是 http://127.0.0.1:9000/#/ ...我尝试了很多东西,但没有任何效果...我总是被重定向到那个地方。

这是我的文件:

httpd.conf

<VirtualHost *:80>
    DocumentRoot "/Users/myusername/Sites/MyApp/app"
    ServerName myapp.dev
    <Directory "/Users/myusername/Sites/MyApp/app">
    Options FollowSymLinks MultiViews Indexes
    AllowOverride All
    Order allow,deny
    Deny from none
    Allow from all
    </Directory>
</VirtualHost>

主机

127.0.0.1 myapp.dev
::1 myapp.dev

Gruntfile.js

// Generated on 2013-11-08 using generator-angular 0.5.1
'use strict';

// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/,*/*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'

module.exports = function (grunt) 
  require('load-grunt-tasks')(grunt);
  require('time-grunt')(grunt);

  grunt.initConfig(
    yeoman: 
      // configurable paths
      app: require('./bower.json').appPath || 'app',
      dist: 'dist'
    ,
    watch: 
      coffee: 
        files: ['<%= yeoman.app %>/scripts/,*/*.coffee'],
        tasks: ['coffee:dist']
      ,
      coffeeTest: 
        files: ['test/spec/,*/*.coffee'],
        tasks: ['coffee:test']
      ,
      compass: 
        files: ['<%= yeoman.app %>/styles/,*/*.scss,sass'],
        tasks: ['compass:server', 'autoprefixer']
      ,
      styles: 
        files: ['<%= yeoman.app %>/styles/,*/*.css'],
        tasks: ['copy:styles', 'autoprefixer']
      ,
      livereload: 
        options: 
          livereload: '<%= connect.options.livereload %>'
        ,
        files: [
          '<%= yeoman.app %>/,*/*.html',
          '.tmp/styles/,*/*.css',
          '.tmp,<%= yeoman.app %>/scripts/,*/*.js',
          '<%= yeoman.app %>/images/,*/*.png,jpg,jpeg,gif,webp,svg'
        ]
      
    ,
    autoprefixer: 
      options: ['last 1 version'],
      dist: 
        files: [
          expand: true,
          cwd: '.tmp/styles/',
          src: ',*/*.css',
          dest: '.tmp/styles/'
        ]
      
    ,
    connect: 
      options: 
        port: 9000,
        // Change this to '0.0.0.0' to access the server from outside.
        hostname: 'myapp.dev',
        livereload: 35729
      ,
      livereload: 
        options: 
          open: true,
          base: [
            '.tmp',
            '<%= yeoman.app %>'
          ]
        
      ,
      test: 
        options: 
          port: 9001,
          base: [
            '.tmp',
            'test',
            '<%= yeoman.app %>'
          ]
        
      ,
      dist: 
        options: 
          base: '<%= yeoman.dist %>'
        
      
    ,
    clean: 
      dist: 
        files: [
          dot: true,
          src: [
            '.tmp',
            '<%= yeoman.dist %>/*',
            '!<%= yeoman.dist %>/.git*'
          ]
        ]
      ,
      server: '.tmp'
    ,
    jshint: 
      options: 
        jshintrc: '.jshintrc'
      ,
      all: [
        'Gruntfile.js',
        '<%= yeoman.app %>/scripts/,*/*.js'
      ]
    ,
    coffee: 
      options: 
        sourceMap: true,
        sourceRoot: ''
      ,
      dist: 
        files: [
          expand: true,
          cwd: '<%= yeoman.app %>/scripts',
          src: ',*/*.coffee',
          dest: '.tmp/scripts',
          ext: '.js'
        ]
      ,
      test: 
        files: [
          expand: true,
          cwd: 'test/spec',
          src: ',*/*.coffee',
          dest: '.tmp/spec',
          ext: '.js'
        ]
      
    ,
    compass: 
      options: 
        sassDir: '<%= yeoman.app %>/styles',
        cssDir: '.tmp/styles',
        generatedImagesDir: '.tmp/images/generated',
        imagesDir: '<%= yeoman.app %>/images',
        javascriptsDir: '<%= yeoman.app %>/scripts',
        fontsDir: '<%= yeoman.app %>/styles/fonts',
        importPath: '<%= yeoman.app %>/bower_components',
        httpImagesPath: '/images',
        httpGeneratedImagesPath: '/images/generated',
        httpFontsPath: '/styles/fonts',
        relativeAssets: false
      ,
      dist: ,
      server: 
        options: 
          debugInfo: true
        
      
    ,
    // not used since Uglify task does concat,
    // but still available if needed
    /*concat: 
      dist: 
    ,*/
    rev: 
      dist: 
        files: 
          src: [
            '<%= yeoman.dist %>/scripts/,*/*.js',
            '<%= yeoman.dist %>/styles/,*/*.css',
            '<%= yeoman.dist %>/images/,*/*.png,jpg,jpeg,gif,webp,svg',
            '<%= yeoman.dist %>/styles/fonts/*'
          ]
        
      
    ,
    useminPrepare: 
      html: '<%= yeoman.app %>/index.html',
      options: 
        dest: '<%= yeoman.dist %>'
      
    ,
    usemin: 
      html: ['<%= yeoman.dist %>/,*/*.html'],
      css: ['<%= yeoman.dist %>/styles/,*/*.css'],
      options: 
        dirs: ['<%= yeoman.dist %>']
      
    ,
    imagemin: 
      dist: 
        files: [
          expand: true,
          cwd: '<%= yeoman.app %>/images',
          src: ',*/*.png,jpg,jpeg',
          dest: '<%= yeoman.dist %>/images'
        ]
      
    ,
    svgmin: 
      dist: 
        files: [
          expand: true,
          cwd: '<%= yeoman.app %>/images',
          src: ',*/*.svg',
          dest: '<%= yeoman.dist %>/images'
        ]
      
    ,
    cssmin: 
      // By default, your `index.html` <!-- Usemin Block --> will take care of
      // minification. This option is pre-configured if you do not wish to use
      // Usemin blocks.
      // dist: 
      //   files: 
      //     '<%= yeoman.dist %>/styles/main.css': [
      //       '.tmp/styles/,*/*.css',
      //       '<%= yeoman.app %>/styles/,*/*.css'
      //     ]
      //   
      // 
    ,
    htmlmin: 
      dist: 
        options: 
          /*removeCommentsFromCDATA: true,
          // https://github.com/yeoman/grunt-usemin/issues/44
          //collapseWhitespace: true,
          collapseBooleanAttributes: true,
          removeAttributeQuotes: true,
          removeRedundantAttributes: true,
          useShortDoctype: true,
          removeEmptyAttributes: true,
          removeOptionalTags: true*/
        ,
        files: [
          expand: true,
          cwd: '<%= yeoman.app %>',
          src: ['*.html', 'views/*.html'],
          dest: '<%= yeoman.dist %>'
        ]
      
    ,
    // Put files not handled in other tasks here
    copy: 
      dist: 
        files: [
          expand: true,
          dot: true,
          cwd: '<%= yeoman.app %>',
          dest: '<%= yeoman.dist %>',
          src: [
            '*.ico,png,txt',
            '.htaccess',
            'bower_components/**/*',
            'images/,*/*.gif,webp',
            'styles/fonts/*'
          ]
        , 
          expand: true,
          cwd: '.tmp/images',
          dest: '<%= yeoman.dist %>/images',
          src: [
            'generated/*'
          ]
        ]
      ,
      styles: 
        expand: true,
        cwd: '<%= yeoman.app %>/styles',
        dest: '.tmp/styles/',
        src: ',*/*.css'
      
    ,
    concurrent: 
      server: [
        'coffee:dist',
        'compass:server',
        'copy:styles'
      ],
      test: [
        'coffee',
        'compass',
        'copy:styles'
      ],
      dist: [
        'coffee',
        'compass:dist',
        'copy:styles',
        'imagemin',
        'svgmin',
        'htmlmin'
      ]
    ,
    karma: 
      unit: 
        configFile: 'karma.conf.js',
        singleRun: true
      
    ,
    cdnify: 
      dist: 
        html: ['<%= yeoman.dist %>/*.html']
      
    ,
    ngmin: 
      dist: 
        files: [
          expand: true,
          cwd: '<%= yeoman.dist %>/scripts',
          src: '*.js',
          dest: '<%= yeoman.dist %>/scripts'
        ]
      
    ,
    uglify: 
      dist: 
        files: 
          '<%= yeoman.dist %>/scripts/scripts.js': [
            '<%= yeoman.dist %>/scripts/scripts.js'
          ]
        
      
    
  );

  grunt.registerTask('server', function (target) 
    if (target === 'dist') 
      return grunt.task.run(['build', 'connect:dist:keepalive']);
    

    grunt.task.run([
      'clean:server',
      'concurrent:server',
      'autoprefixer',
      'connect:livereload',
      'watch'
    ]);
  );

  grunt.registerTask('test', [
    'clean:server',
    'concurrent:test',
    'autoprefixer',
    'connect:test',
    'karma'
  ]);

  grunt.registerTask('build', [
    'clean:dist',
    'useminPrepare',
    'concurrent:dist',
    'autoprefixer',
    'concat',
    'copy:dist',
    'cdnify',
    'ngmin',
    'cssmin',
    'uglify',
    'rev',
    'usemin'
  ]);

  grunt.registerTask('default', [
    'jshint',
    'test',
    'build'
  ]);
;

【问题讨论】:

【参考方案1】:

这里不需要 Apache。 Connect 是一个 Web 服务器,因此它已经为您的静态文件提供服务。尝试禁用 Apache 并将您的 hostname 选项更改为 localhost。

【讨论】:

【参考方案2】:

@Dmitry Nikitenko 是正确的,您不需要 Apache。你需要改变你的 Gruntfile

hostname 选项仅用于指定 livereload 应连接到的位置。这不会更改启动 Grunt 时打开的默认 url。您需要在 livereload 选项中为 open 指定一个 URL。例如:

  livereload: 
    options: 
      open: 'http://myapp.dev:9000',
      base: [
        '.tmp',
        '<%= yeoman.app %>'
      ]
    

【讨论】:

用于将 ip 重定向到主机名的 Apache httpd.conf

...2【问题描述】:我为我的机器配置了外部IP和主机名。在应用程序内部,我只使用域名来访问API。因此,当我尝试通过IP地址访问我的API时,它会显示302Moved临时错误。因此,对于使用IP地址访问服务器的请求(对于主页),它应... 查看详情

Grunt 中的 NodeJS 环境变量

...nodeserver.js转移到使用Grunt。我以前直接从webstorm运行我的应用程序,并且会为我设置环境变量。我怎样才能在Grunt中达到同样的效果?我需要从webstorm(windows)运行grunt,或者在运行grunt 查看详情

Express 可以在使用虚拟主机时运行 Gulp 或 Grunt 任务吗?

】Express可以在使用虚拟主机时运行Gulp或Grunt任务吗?【英文标题】:CanExpressrunGulporGrunttaskswhenusingvhosts?【发布时间】:2014-06-2203:17:43【问题描述】:我通常使用Gulp启动我的NodeJS服务器,任务类似于:gulp.task(\'server\',function()varpor... 查看详情

为我的应用程序需要与之通信的每个主机使用一个 HttpClient 实例是不是可以?

】为我的应用程序需要与之通信的每个主机使用一个HttpClient实例是不是可以?【英文标题】:IsitfinetouseoneHttpClientinstanceforeachhostmyapplicationneedstotalkto?为我的应用程序需要与之通信的每个主机使用一个HttpClient实例是否可以?【发... 查看详情

本地主机为我的 Angular 应用程序发送了无效响应

】本地主机为我的Angular应用程序发送了无效响应【英文标题】:Localhostsentaninvalidresponseformyangularapp【发布时间】:2019-03-1116:25:55【问题描述】:我在本地有一个使用springBoot、java、jHipster、Angular等创建的项目,我想运行它。通常... 查看详情

应用程序在“grunt build”后停止工作(控制台中没有错误)

】应用程序在“gruntbuild”后停止工作(控制台中没有错误)【英文标题】:Appstopworking(withnoerrorsinconsole)after"gruntbuild"【发布时间】:2015-05-2717:02:39【问题描述】:我正在使用yeoman+bower+grunt构建一个AngularJS应用程序。在我... 查看详情

正确发布一个 grunt 项目

...经常使用Mavenreleaseplugin将我构建的工件部署到Nexus。我想为我的使用Grunt构建的Web项目找到一个等价物。目前,我使用grunt-maven-tasks将工件部署到Ne 查看详情

ReactJs 如何传递自定义服务器主机名?

...2019-01-0500:21:33【问题描述】:我希望能够在运行我的react应用程序时传递一个自定义服务器主机名,以便在我需要获取数据时在url中使用。服务器当前正在我的本地计算机上运行,​​所以当我fetch(url)时,我一直在使用“http://lo... 查看详情

将节点检查器与 Grunt 任务一起使用

...-06-2515:02:54【问题描述】:有人使用node-inspector和Grunt进行应用程序调试吗?如果没有,你能推荐一个基于Grunt的应用程序的调试工具吗?我正在为服务器端应用程序使用nodejs,并且我有Grunt使用单独的任务(这是因为用户可以单... 查看详情

如何找出我的主机为我安装的邮件服务器?

】如何找出我的主机为我安装的邮件服务器?【英文标题】:HowdoIfindoutwhatmail-servermyhosthasinstalledforme?【发布时间】:2010-09-2202:12:50【问题描述】:我正在使用MediaTemple的(dv)托管服务。如何确定安装了哪些邮件服务器?我应该使... 查看详情

使用 grunt 服务器,如何将所有请求重定向到根 url?

...-06-0910:48:47【问题描述】:我正在构建我的第一个Angular.js应用程序,我正在使用Yeoman。Yeoman使用Grunt允许您使用命令“gruntserver”运行node.js连接服务器。我在html5模式下运行我的A 查看详情

部署到 EB 的 Django 应用程序无法翻译主机名

】部署到EB的Django应用程序无法翻译主机名【英文标题】:DjangoAppdeployedtoEBCouldnottranslatehostname【发布时间】:2020-12-0622:48:14【问题描述】:我尝试在创建用户对象后发送电子邮件。我用芹菜来执行任务。我的应用程序被部署到AWS... 查看详情

grunt-nodemon 没有使用 nodemon 来启动服务器

】grunt-nodemon没有使用nodemon来启动服务器【英文标题】:grunt-nodemondidn\'tusenodemontostartserver【发布时间】:2014-05-2709:32:32【问题描述】:我使用express-generator创建项目骨架,并使用jade、sass代替ejs和stylus,然后我使用concurrent组合watc... 查看详情

Grunt,Livereload 与 Maven 和码头服务器

...述】:我想知道是否可以在我当前使用maven和jetty的javaweb应用程序中使用grunt和livereload?我当前的javaweb应用程序的工作方式是我运行maven来构建webapp,它还创建了一个本地码头服务器,我的 查看详情

如何使用 grunt 部署 Angular 2?

...2017-08-1413:54:28【问题描述】:我正在尝试构建一个Angular2应用程序,并且我想使用Grunt来部署它。出于某种原因,当我运行部署的index.html时,我的代码不起作用。有问题的代码是来自Angular网站的示例。我假设我要么缺少依赖项,... 查看详情

我正在为我的 ASP.NET MVC 程序使用 DataTables 插件。该表显示没有任何 CSS。为啥?

】我正在为我的ASP.NETMVC程序使用DataTables插件。该表显示没有任何CSS。为啥?【英文标题】:I\'musingaDataTablespluginformyASP.NETMVCprogram.ThetabledisplayswithoutanyCSS.Why?我正在为我的ASP.NETMVC程序使用DataTables插件。该表显示没有任何CSS。为什... 查看详情

Nodejs 服务器主机名

】Nodejs服务器主机名【英文标题】:NodejsServerHostname【发布时间】:2012-09-1517:42:19【问题描述】:好的,所以在Node.js中获取向我的服务器发出的请求的主机名似乎很容易:app.get(\'/\',function(req,res)console.log(req.headers.host););有没有一... 查看详情

在 mac os 中安装 Grunt

...4-12-0116:24:21【问题描述】:我想使用引导程序创建Angularjs应用程序,为此我在我的mac中安装了node.jspkg文件。之后我安装了yeoman($sudonpminstall--globalyo)。文档说,如果我们安装yo,那么我们会自动安装grunt和bower。在我的情况下,没... 查看详情