:recycle: [Refactor] Separate endpoints configs
Browse files- .gitignore +1 -1
- configs/endpoints.json +8 -0
- server.js +8 -5
.gitignore
CHANGED
@@ -2,4 +2,4 @@ node_modules
|
|
2 |
package-lock.json
|
3 |
.vscode
|
4 |
live.js
|
5 |
-
|
|
|
2 |
package-lock.json
|
3 |
.vscode
|
4 |
live.js
|
5 |
+
# configs/endpoints.json
|
configs/endpoints.json
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[
|
2 |
+
{
|
3 |
+
"endpoint": "https://hansimov-hf-llm-api.hf.space",
|
4 |
+
"api_key": "sk-xxxxx",
|
5 |
+
"api_type": "openai",
|
6 |
+
"need_protect": true
|
7 |
+
}
|
8 |
+
]
|
server.js
CHANGED
@@ -15,15 +15,18 @@ app.get("/", (req, res) => {
|
|
15 |
|
16 |
app.get("/endpoints", async (req, res) => {
|
17 |
try {
|
18 |
-
let
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
22 |
res.json(local_points);
|
23 |
} catch (error) {
|
24 |
console.error(error);
|
25 |
res.status(500).json({
|
26 |
-
error: "Failed to get local endpoints: Maybe
|
27 |
});
|
28 |
}
|
29 |
});
|
|
|
15 |
|
16 |
app.get("/endpoints", async (req, res) => {
|
17 |
try {
|
18 |
+
let endpoints_configs_path = path.join(
|
19 |
+
__dirname,
|
20 |
+
"configs",
|
21 |
+
"endpoints.json"
|
22 |
+
);
|
23 |
+
const data = await fs.readFile(endpoints_configs_path, "utf-8");
|
24 |
+
const local_points = JSON.parse(data);
|
25 |
res.json(local_points);
|
26 |
} catch (error) {
|
27 |
console.error(error);
|
28 |
res.status(500).json({
|
29 |
+
error: "Failed to get local endpoints: Maybe configs/endpoints.json not existed?",
|
30 |
});
|
31 |
}
|
32 |
});
|