Skip to content

Commit 82e0c1d

Browse files
committed
[fix] move backend entpoints to /api to avoid conflicts with client side routing
1 parent 91d9a25 commit 82e0c1d

3 files changed

Lines changed: 22 additions & 12 deletions

File tree

server/api.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,24 @@ func init() {
6464
Handler: serveSearch,
6565
Description: "Search websocket endpoint",
6666
},
67+
// tmp added for backward compatibility
6768
&Endpoint{
6869
Name: "Add",
69-
Path: "/add",
70+
Path: "/api/add",
7071
Method: GET,
7172
CSRFRequired: true,
7273
Handler: serveAdd,
7374
Description: "Add document form",
7475
},
76+
&Endpoint{
77+
Name: "Add post",
78+
Path: "/api/add",
79+
Method: POST,
80+
CSRFRequired: true,
81+
Handler: serveAdd,
82+
Description: "Save added document",
83+
},
84+
// alias for /api/add - backward compatibility - use /api/add in the future
7585
&Endpoint{
7686
Name: "Add post",
7787
Path: "/add",
@@ -82,7 +92,7 @@ func init() {
8292
},
8393
&Endpoint{
8494
Name: "Get document",
85-
Path: "/document",
95+
Path: "/api/document",
8696
Method: GET,
8797
CSRFRequired: false,
8898
Handler: serveGet,
@@ -98,63 +108,63 @@ func init() {
98108
},
99109
&Endpoint{
100110
Name: "Rules",
101-
Path: "/rules",
111+
Path: "/api/rules",
102112
Method: GET,
103113
CSRFRequired: true,
104114
Handler: serveRules,
105115
Description: "Rules page",
106116
},
107117
&Endpoint{
108118
Name: "Save rules",
109-
Path: "/rules",
119+
Path: "/api/rules",
110120
Method: POST,
111121
CSRFRequired: true,
112122
Handler: serveRules,
113123
Description: "Save rules",
114124
},
115125
&Endpoint{
116126
Name: "History",
117-
Path: "/history",
127+
Path: "/api/history",
118128
Method: GET,
119129
CSRFRequired: true,
120130
Handler: serveHistory,
121131
Description: "History page",
122132
},
123133
&Endpoint{
124134
Name: "Add history item",
125-
Path: "/history",
135+
Path: "/api/history",
126136
Method: POST,
127137
CSRFRequired: true,
128138
Handler: serveHistory,
129139
Description: "Add new history item",
130140
},
131141
&Endpoint{
132142
Name: "Delete",
133-
Path: "/delete",
143+
Path: "/api/delete",
134144
Method: POST,
135145
CSRFRequired: true,
136146
Handler: serveDeleteDocument,
137147
Description: "Delete document endpoint",
138148
},
139149
&Endpoint{
140150
Name: "Delete alias",
141-
Path: "/delete_alias",
151+
Path: "/api/delete_alias",
142152
Method: POST,
143153
CSRFRequired: true,
144154
Handler: serveDeleteAlias,
145155
Description: "Delete alias",
146156
},
147157
&Endpoint{
148158
Name: "Add alias",
149-
Path: "/add_alias",
159+
Path: "/api/add_alias",
150160
Method: POST,
151161
CSRFRequired: true,
152162
Handler: serveAddAlias,
153163
Description: "Add alias",
154164
},
155165
&Endpoint{
156166
Name: "Readable",
157-
Path: "/readable",
167+
Path: "/api/readable",
158168
Method: GET,
159169
CSRFRequired: false,
160170
Handler: serveReadable,

webui/app/src/lib/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export async function apiFetch(
3535
if (_csrf && options.method && options.method.toUpperCase() !== 'GET') {
3636
headers['X-CSRF-Token'] = _csrf;
3737
}
38-
const res = await fetch(url, { ...options, headers });
38+
const res = await fetch("/api"+url, { ...options, headers });
3939
const newTok = res.headers.get('X-CSRF-Token');
4040
if (newTok) _csrf = newTok;
4141
return res;

webui/app/src/lib/search.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ export function apiRequest(options: APIRequestOptions): void {
263263
body: options.params?.body as BodyInit,
264264
};
265265

266-
fetch(options.url, params).then((r) => {
266+
fetch("/api"+options.url, params).then((r) => {
267267
const newToken = r.headers.get("X-CSRF-Token");
268268
if (newToken && options.csrfToken !== undefined) {
269269
options.csrfCallback?.(newToken);

0 commit comments

Comments
 (0)