【问题标题】:Send Request To Apache Tomcat (localhost:8080) using GruntJs使用 GruntJs 向 Apache Tomcat (localhost:8080) 发送请求
【发布时间】:2015-10-01 12:42:51
【问题描述】:

您好,我有一些架构,我使用 grunt 构建的前端应用程序,它在 localhost:3000 nodejs 服务器上运行,我的后端应用程序在 Apache tomcat 服务器 (localhost:8080) 中。基本上是在 spring 框架上运行的后端应用程序。伙计们,我想使用 gruntjs 从我的 localhost:3000 向 localhost:8080 发送请求。

请帮帮我。

这是我的 grunt js 文件

module.exports = function(grunt){

    grunt.initConfig({
        concat: {
            options: {
                separator   : '\n\n//--------------------------------------------------\n\n;',
                banner      : '\n\n//---------------All Js file is here ---------------\n\n'
            },
            dist :{
                src :['components/scripts/*.js'],
                dest:'builds/development/js/scripts.js'
            }

        },
        sass : {
            dist :{
                options:{
                    style:'expanded'
                },
                files:[{
                    src:'components/sass/style.scss',
                    dest:'builds/development/css/style.css'
                }]
            }
        },
        connect:{
            server:{
                options:{
                    hostname:'localhost',
                    port:'3000',
                    base:'builds/development/',
                    livereload:true
                }
            }
        },
        watch: {
              scripts: {
                files: ['builds/development/**/*.html',
                        'components/scripts/**/*.js',
                        'components/sass/**/*.scss'],
                tasks: ['concat','sass'],
                options: {
                  spawn: false,
                  livereload:true
                },
              },
            }
    });

    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-sass');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-connect');

    grunt.registerTask('default',['concat','sass','connect','watch']);
};

【问题讨论】:

    标签: node.js apache tomcat jakarta-ee gruntjs


    【解决方案1】:

    要解决您的问题,您必须编写单独的节点服务器并注册 grunt 任务。

    var http = require('http');
    var httpProxy = require('http-proxy');
    
    var server = http.createServer(function(){
        httpProxy.createProxyServer({target: 'http://localhost:8080'}).web(req, res);
    });
    
    module.exports = function(grunt) {
        grunt.registerTask('server', function() {
            // this.async(); // run forever
            server.listen(8000);// Front End Server Listening Port
        });
    };
    

    【讨论】:

      猜你喜欢
      • 2023-04-01
      • 2019-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-28
      • 2018-01-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多