fix(source): add /services/{name}/source endpoint; fix 404 for service code view in funcs-console
This commit is contained in:
@@ -416,7 +416,7 @@
|
||||
icon.style.transform = 'rotate(90deg)';
|
||||
if (!loaded) {
|
||||
loaded = true;
|
||||
loadSource(body, ns, fn.name);
|
||||
loadSource(body, ns, fn.name, fn.kind);
|
||||
}
|
||||
} else {
|
||||
body.style.display = 'none';
|
||||
@@ -458,12 +458,13 @@
|
||||
return btn;
|
||||
}
|
||||
|
||||
function loadSource(body, ns, fnName) {
|
||||
function loadSource(body, ns, fnName, fnKind) {
|
||||
var msg = $el('div', 'src-msg');
|
||||
msg.textContent = 'Загрузка кода…';
|
||||
body.appendChild(msg);
|
||||
|
||||
fetch('/funcs/' + ns + '/source/' + fnName)
|
||||
var kindParam = fnKind === 'service' ? '?kind=service' : '';
|
||||
fetch('/funcs/' + ns + '/source/' + fnName + kindParam)
|
||||
.then(function (r) {
|
||||
body.removeChild(msg);
|
||||
if (!r.ok) {
|
||||
|
||||
@@ -347,14 +347,19 @@ func servePlainText(w http.ResponseWriter, ns, externalURL string, fns []fnRespo
|
||||
fmt.Fprint(w, sb.String())
|
||||
}
|
||||
|
||||
// proxySourceGet проксирует GET /funcs/{ns}/source/{fn} → оператор GET /v1/.../source.
|
||||
// proxySourceGet проксирует GET /funcs/{ns}/source/{fn}?kind={function|service} → оператор.
|
||||
// Авторизация — сервисный токен (хранится на сервере, не открывается клиенту).
|
||||
// kind=service → /v1/.../services/{fn}/source; иначе → /v1/.../functions/{fn}/source
|
||||
func proxySourceGet(w http.ResponseWriter, r *http.Request, operatorURL, serviceToken, ns, funcName string) {
|
||||
if !isValidK8sName(funcName) {
|
||||
http.Error(w, "invalid function name\n", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
target := operatorURL + "/v1/namespaces/" + ns + "/functions/" + funcName + "/source"
|
||||
resourceType := "functions"
|
||||
if r.URL.Query().Get("kind") == "service" {
|
||||
resourceType = "services"
|
||||
}
|
||||
target := operatorURL + "/v1/namespaces/" + ns + "/" + resourceType + "/" + funcName + "/source"
|
||||
req, err := http.NewRequestWithContext(r.Context(), http.MethodGet, target, nil)
|
||||
if err != nil {
|
||||
http.Error(w, "internal error\n", http.StatusInternalServerError)
|
||||
|
||||
Reference in New Issue
Block a user