MoMo commited on
Commit
f84f64a
·
1 Parent(s): a9e1abe
Files changed (4) hide show
  1. Dockerfile +2 -2
  2. api/src/.env +3 -1
  3. api/src/config.js +2 -1
  4. api/src/core/api.js +23 -1
Dockerfile CHANGED
@@ -31,8 +31,8 @@ COPY --from=build --chown=node:node /app/.git /app/.git
31
 
32
  USER node
33
 
34
- ENV API_URL="https://hhaoqin-cobalt.hf.space/"
35
- ENV API_PORT="7860"
36
 
37
  EXPOSE 7860
38
  CMD [ "node", "src/cobalt" ]
 
31
 
32
  USER node
33
 
34
+ #ENV API_URL="https://hhaoqin-cobalt.hf.space/"
35
+ #ENV API_PORT="7860"
36
 
37
  EXPOSE 7860
38
  CMD [ "node", "src/cobalt" ]
api/src/.env CHANGED
@@ -1 +1,3 @@
1
- API_URL="https://hhaoqin-cobalt.hf.space/"
 
 
 
1
+ API_URL="https://hhaoqin-cobalt.hf.space/"
2
+ APPKEY="SL0qaUL2dAdzaIpduOuBSg"
3
+ API_PORT="7860"
api/src/config.js CHANGED
@@ -13,9 +13,10 @@ const enabledServices = new Set(Object.keys(services).filter(e => {
13
  }));
14
 
15
  const env = {
16
- apiURL: process.env.API_URL || 'https://hhaoqin-cobalt.hf.space/',
17
  apiPort: process.env.API_PORT || 7860,
18
  tunnelPort: process.env.API_PORT || 7860,
 
19
 
20
  listenAddress: process.env.API_LISTEN_ADDRESS,
21
  freebindCIDR: process.platform === 'linux' && process.env.FREEBIND_CIDR,
 
13
  }));
14
 
15
  const env = {
16
+ apiURL: process.env.API_URL || '',
17
  apiPort: process.env.API_PORT || 7860,
18
  tunnelPort: process.env.API_PORT || 7860,
19
+ appKey: process.env.APPKEY,
20
 
21
  listenAddress: process.env.API_LISTEN_ADDRESS,
22
  freebindCIDR: process.platform === 'linux' && process.env.FREEBIND_CIDR,
api/src/core/api.js CHANGED
@@ -128,6 +128,20 @@ export const runAPI = async (express, app, __dirname, isPrimary = true) => {
128
  next();
129
  });
130
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  app.post('/', (req, res, next) => {
132
  if (!env.apiKeyURL) {
133
  return next();
@@ -170,7 +184,7 @@ export const runAPI = async (express, app, __dirname, isPrimary = true) => {
170
  return fail(res, "error.api.auth.jwt.invalid");
171
  }
172
 
173
- const [ type, token, ...rest ] = authorization.split(" ");
174
  if (!token || type.toLowerCase() !== 'bearer' || rest.length) {
175
  return fail(res, "error.api.auth.jwt.invalid");
176
  }
@@ -321,6 +335,14 @@ export const runAPI = async (express, app, __dirname, isPrimary = true) => {
321
  app.get('/itunnel', itunnelHandler);
322
 
323
  app.get('/', (_, res) => {
 
 
 
 
 
 
 
 
324
  res.type('json');
325
  res.status(200).send(serverInfo);
326
  })
 
128
  next();
129
  });
130
 
131
+ app.post('/', (req, res, next) => {
132
+ const appkey = req.query.appkey;
133
+
134
+ if (!appkey) {
135
+ return fail(res, "error.api.auth.appkey.missing");
136
+ }
137
+
138
+ if (appkey !== env.appKey) {
139
+ return fail(res, "error.api.auth.appkey.invalid");
140
+ }
141
+
142
+ next();
143
+ });
144
+
145
  app.post('/', (req, res, next) => {
146
  if (!env.apiKeyURL) {
147
  return next();
 
184
  return fail(res, "error.api.auth.jwt.invalid");
185
  }
186
 
187
+ const [type, token, ...rest] = authorization.split(" ");
188
  if (!token || type.toLowerCase() !== 'bearer' || rest.length) {
189
  return fail(res, "error.api.auth.jwt.invalid");
190
  }
 
335
  app.get('/itunnel', itunnelHandler);
336
 
337
  app.get('/', (_, res) => {
338
+ res.type('json');
339
+ res.status(200).send(JSON.stringify({
340
+ status: 'success',
341
+ message: 'Hello, world!'
342
+ }));
343
+ })
344
+
345
+ app.get('/api-status', (_, res) => {
346
  res.type('json');
347
  res.status(200).send(serverInfo);
348
  })