可以達到使用目標咕嚕-連接重寫,只是把它作爲一個最後的中間件。但我建議你使用https://www.npmjs.org/package/http-rewrite-middleware istead更靈活的解決方案......
即最終的解決方案可能是這樣的:
var rewriteModule = require('http-rewrite-middleware');
//...
grunt.initConfig({
connect: {
options: {
port: 9000,
hostname: 'localhost'
},
development: {
options: {
middleware: function (connect, options) {
var middlewares = [];
if (!Array.isArray(options.base)) {
options.base = [options.base];
}
var directory = options.directory || options.base[options.base.length - 1];
options.base.forEach(function (base) {
// Serve static files.
middlewares.push(connect.static(base));
});
// Make directory browse-able.
middlewares.push(connect.directory(directory));
// ... everything else here
// RewriteRules support
middlewares.push(rewriteModule.getMiddleware([
{from: '^(.*)-dbg.js', to: '$1.js'}
]));
return middlewares;
}
}
}
}
});