|
@@ -5,9 +5,11 @@
|
|
|
<thead>
|
|
|
<tr>
|
|
|
<th>Redirection URL</th>
|
|
|
+ <th></th>
|
|
|
<th>Destination URL</th>
|
|
|
<th>Copy Pathname</th>
|
|
|
<th>Status Code</th>
|
|
|
+ <th>Remove</th>
|
|
|
</tr>
|
|
|
</thead>
|
|
|
<tbody id="redirectionRuleList">
|
|
@@ -19,6 +21,9 @@
|
|
|
</tr>
|
|
|
</tbody>
|
|
|
</table>
|
|
|
+ <div class="ui green message" id="delRuleSucc" style="display:none;">
|
|
|
+ <i class="ui green checkmark icon"></i> Redirection Rule Deleted
|
|
|
+ </div>
|
|
|
</div>
|
|
|
<div class="ui divider"></div>
|
|
|
<p>Add path redirection to your domain</p>
|
|
@@ -26,12 +31,13 @@
|
|
|
<div class="ui form">
|
|
|
<div class="field">
|
|
|
<label>Redirection URL</label>
|
|
|
- <input type="text" name="redirection-url" placeholder="Redirection URL">
|
|
|
- <small><i class="ui circle info icon"></i> Redirection URL, any matching prefix of the request URL will be redirected to the following destination URL.</small>
|
|
|
+ <input type="text" id="rurl" name="redirection-url" placeholder="Redirection URL">
|
|
|
+ <small><i class="ui circle info icon"></i> Any matching prefix of the request URL will be redirected to the destination URL, e.g. redirect.example.com</small>
|
|
|
</div>
|
|
|
<div class="field">
|
|
|
<label>Destination URL</label>
|
|
|
<input type="text" name="destination-url" placeholder="Destination URL">
|
|
|
+ <small><i class="ui circle info icon"></i> The target URL request being redirected to, e.g. dest.example.com/mysite</small>
|
|
|
</div>
|
|
|
<div class="field">
|
|
|
<div class="ui checkbox">
|
|
@@ -59,7 +65,10 @@
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
- <button class="ui button" onclick="addRules();">Add</button>
|
|
|
+ <button class="ui teal button" onclick="addRules();"><i class="ui plus icon"></i> Add Redirection Rule</button>
|
|
|
+ <div class="ui green message" id="ruleAddSucc" style="display:none;">
|
|
|
+ <i class="ui green checkmark icon"></i> Redirection Rules Added
|
|
|
+ </div>
|
|
|
</div>
|
|
|
<script>
|
|
|
$(".checkbox").checkbox();
|
|
@@ -80,30 +89,63 @@
|
|
|
redirectType: parseInt(redirectType),
|
|
|
},
|
|
|
success: function(data){
|
|
|
- alert(data);
|
|
|
+ if (data.error != undefined){
|
|
|
+ alert(data.error);
|
|
|
+ }else{
|
|
|
+ $("#ruleAddSucc").stop().finish().slideDown("fast").delay(3000).slideUp("fast");
|
|
|
+ }
|
|
|
+ initRedirectionRuleList();
|
|
|
}
|
|
|
- })
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- function deleteRule(redirectDomain){
|
|
|
-
|
|
|
+ function deleteRule(obj){
|
|
|
+ let targetURL = $(obj).attr("rurl");
|
|
|
+ targetURL = JSON.parse(decodeURIComponent(targetURL));
|
|
|
+ if (confirm("Confirm remove redirection from " + targetURL + " ?")){
|
|
|
+ $.ajax({
|
|
|
+ url: "/redirect/delete",
|
|
|
+ method: "POST",
|
|
|
+ data: {
|
|
|
+ redirectUrl: targetURL,
|
|
|
+ },
|
|
|
+ success: function(data){
|
|
|
+ if (data.error != undefined){
|
|
|
+ alert(data.error);
|
|
|
+ }else{
|
|
|
+ $("#delRuleSucc").stop().finish().slideDown("fast").delay(3000).slideUp("fast");
|
|
|
+ }
|
|
|
+ initRedirectionRuleList();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
function initRedirectionRuleList(){
|
|
|
$("#redirectionRuleList").html("");
|
|
|
$.get("/redirect/list", function(data){
|
|
|
- console.log(data);
|
|
|
data.forEach(function(entry){
|
|
|
$("#redirectionRuleList").append(`<tr>
|
|
|
- <td>${entry.RedirectURL}</td>
|
|
|
+ <td>${entry.RedirectURL} </td>
|
|
|
+ <td style="text-align: center;"><i class="blue arrow right icon"></i></td>
|
|
|
<td>${entry.TargetURL}</td>
|
|
|
<td>${entry.ForwardChildpath?"<i class='ui green checkmark icon'></i>":"<i class='ui red remove icon'></i>"}</td>
|
|
|
<td>${entry.StatusCode==307?"Temporary Redirect (307)":"Moved Permanently (301)"}</td>
|
|
|
+ <td><button onclick="deleteRule(this);" rurl="${encodeURIComponent(JSON.stringify(entry.RedirectURL))}" title="Delete redirection rule" class="ui mini red icon basic button"><i class="trash icon"></i></button></td>
|
|
|
</tr>`);
|
|
|
});
|
|
|
+
|
|
|
+ if (data.length == 0){
|
|
|
+ $("#redirectionRuleList").append(`<tr colspan="4"><td><i class="checkmark icon"></i> No redirection rule</td></tr>`);
|
|
|
+ }
|
|
|
|
|
|
});
|
|
|
}
|
|
|
initRedirectionRuleList();
|
|
|
+
|
|
|
+ $("#rurl").on('change', (event) => {
|
|
|
+ const value = event.target.value.trim().replace(/^(https?:\/\/)/, '');
|
|
|
+ event.target.value = value;
|
|
|
+ });
|
|
|
|
|
|
</script>
|