我们如何使用node.js connect映射路径

时间:2013-03-21 01:29:59

标签: node.js connect middleware gruntjs

我们如何使用node.js连接中间件将一些路径映射到另一个路径?

例如,我希望我的服务器在fileA请求时以fileB回复。

(用于在grunt-contrib-connect内部使用)

1 个答案:

答案 0 :(得分:0)

我有一种愚蠢的方法,但它是一种方法!

copy: {
    "mount-server": {
        files: [{
            expand: true,
            dot: true,
            cwd: '<%= yeoman.app %>',
            dest: './.mount-server/search/mobileqq/',
            src: [
               '**/**'
            ]
        }]
    }
}
     connect: {
        options: {
            port: 80,
            // change this to '0.0.0.0' to access the server from outside
            hostname: null
        },
        livereload: {
            options: {
                middleware: function (connect, options) {
                    return [
                        lrSnippet,
                        mountFolder(connect, '.tmp'),
                        mountFolder(connect, "./.mount-server/")
                    ];
                }
            }
        }
   }

grunt.registerTask('prepareServer', [
    "clean:mount-server",
    "copy:mount-server"
]);
grunt.registerTask('server', function (target) {
    if (target === 'dist') {
        return grunt.task.run(['build', 'open', 'connect:dist:keepalive']);
    }

    grunt.task.run([
        'concurrent:server',
        "prepareServer",
        'connect:livereload',
        'open:server',
        'watch'
    ]);
});

只需复制你的文件并制作另一个装载文件夹!