node.js - 发送请求到 Apache Tomcat (localhost :8080) using GruntJs

标签 node.js apache tomcat jakarta-ee gruntjs

您好,我有一些架构,我的前端应用程序是使用 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 服务器并注册 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
    });
};

关于node.js - 发送请求到 Apache Tomcat (localhost :8080) using GruntJs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32887907/

相关文章:

tomcat - Spring boot Tomcat – 启用/禁用目录列表

node.js - 如何在 CloudFoundry 上运行 Node 检查器?

node.js - 在周一至周五上午 9 点到下午 5 点之间运行 Node 调度程序

eclipse - Tomcat 关闭时 : WARNING: StandardServer. 等待:收到无效命令 'SHUTDO'

linux - PHP fopen "failed to open stream: resource temporarily unavailable"

linux - 如何检测linux机器上是否安装了tomcat和ant

java - 在GRCC TCG上创建模型

validation - 使用 Backbone.js 验证时如何处理异步调用(特别是唯一性)

node.js - 生产环境中的 Node 服务器必须有 Node 模块吗?

apache - 在 Hybris 中设置 mod_jk 重定向