立馬下載
git clone https://gist.github.com/7210042.git
使用方式 (好讀版)
Step1. 下載 redirect.js 到專案根目錄.
Step2. 編輯 Gruntfile.js
var redirect = require('./redirect');
...
...
connect: {
options: {
port: 9000,
// change this to '0.0.0.0' to access the server from outside
hostname: '0.0.0.0'
},
livereload: {
options: {
middleware: function(connect) {
return [
lrSnippet,
mountFolder(connect, '.tmp'),
mountFolder(connect, 'app'),
redirect('api')
];
}
}
}
},
Step3. redirect 有三個參數. rootDir 是假 api 根目錄. indexFile 是預設連結的檔案. headers 是 http response 的 header,範例:
/app
...
/api
/user
index.json
list.json
...
/Gruntfile.js
...
Step4. run "grunt server"
當讀取 url "/user" 會自動導到根目錄的 "/api/user/index.json"
當讀取 url "/user/list.json" 會自動導到根目錄的 "/api/user/list.json"
相關連結
https://gist.github.com/IskenHuang/7210042
yeoman