mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-03-13 02:20:14 +01:00
Merge pull request #1462 from valadaptive/serpapi-router
Use Express router for serpapi endpoint
This commit is contained in:
commit
fbd4e32caa
@ -3627,7 +3627,7 @@ app.use('/api/extra/classify', require('./src/endpoints/classify').router);
|
|||||||
app.use('/api/extra/caption', require('./src/endpoints/caption').router);
|
app.use('/api/extra/caption', require('./src/endpoints/caption').router);
|
||||||
|
|
||||||
// Web search extension
|
// Web search extension
|
||||||
require('./src/endpoints/serpapi').registerEndpoints(app, jsonParser);
|
app.use('/api/serpapi', require('./src/endpoints/serpapi').router);
|
||||||
|
|
||||||
const tavernUrl = new URL(
|
const tavernUrl = new URL(
|
||||||
(cliArguments.ssl ? 'https://' : 'http://') +
|
(cliArguments.ssl ? 'https://' : 'http://') +
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
const fetch = require('node-fetch').default;
|
const fetch = require('node-fetch').default;
|
||||||
|
const express = require('express');
|
||||||
const { readSecret, SECRET_KEYS } = require('./secrets');
|
const { readSecret, SECRET_KEYS } = require('./secrets');
|
||||||
|
const { jsonParser } = require('../express-common');
|
||||||
|
|
||||||
/**
|
const router = express.Router();
|
||||||
* Registers the SerpApi endpoints.
|
|
||||||
* @param {import("express").Express} app
|
router.post('/search', jsonParser, async (request, response) => {
|
||||||
* @param {any} jsonParser
|
|
||||||
*/
|
|
||||||
function registerEndpoints(app, jsonParser) {
|
|
||||||
app.post('/api/serpapi/search', jsonParser, async (request, response) => {
|
|
||||||
try {
|
try {
|
||||||
const key = readSecret(SECRET_KEYS.SERPAPI);
|
const key = readSecret(SECRET_KEYS.SERPAPI);
|
||||||
|
|
||||||
@ -31,9 +29,6 @@ function registerEndpoints(app, jsonParser) {
|
|||||||
console.log(error);
|
console.log(error);
|
||||||
return response.sendStatus(500);
|
return response.sendStatus(500);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = { router };
|
||||||
registerEndpoints,
|
|
||||||
};
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user