mirror of
https://git.mirrors.martin98.com/https://github.com/jina-ai/reader.git
synced 2025-08-18 02:55:52 +08:00
fix(stand-alone-server): set ip to local context
This commit is contained in:
parent
9dbecbbc9f
commit
7340028c64
@ -53,13 +53,13 @@ export class SerperSearchService extends AsyncService {
|
||||
if (locationChunks.length) {
|
||||
query.location ??= locationChunks.join(', ');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
let maxTries = 3;
|
||||
|
||||
while (maxTries--) {
|
||||
try {
|
||||
this.logger.debug(`Doing external search`, query);
|
||||
const r = await this.serperSearchHTTP.webSearch(query);
|
||||
|
||||
return r.parsed;
|
||||
|
@ -11,7 +11,7 @@ process.env['FIREBASE_CONFIG'] ??= JSON.stringify({
|
||||
initializeApp();
|
||||
|
||||
|
||||
import { Logger, CloudFunctionRegistry } from '../shared';
|
||||
import { Logger, CloudFunctionRegistry, AsyncContext } from '../shared';
|
||||
import { AbstractRPCRegistry, OpenAPIManager } from 'civkit/civ-rpc';
|
||||
import { ExpressServer } from 'civkit/civ-rpc/express';
|
||||
import http2 from 'http2';
|
||||
@ -46,6 +46,7 @@ export class CrawlStandAloneServer extends ExpressServer {
|
||||
protected globalLogger: Logger,
|
||||
protected registry: CloudFunctionRegistry,
|
||||
protected crawlerHost: CrawlerHost,
|
||||
protected threadLocal: AsyncContext,
|
||||
) {
|
||||
super(...arguments);
|
||||
|
||||
@ -98,11 +99,12 @@ export class CrawlStandAloneServer extends ExpressServer {
|
||||
};
|
||||
}
|
||||
|
||||
makeIgnoreOPTIONSMiddleware() {
|
||||
makeMiscMiddleware() {
|
||||
return (req: Request, res: Response, next: NextFunction) => {
|
||||
if (req.method === 'OPTIONS') {
|
||||
return res.status(200).end();
|
||||
}
|
||||
this.threadLocal.set('ip', req.ip);
|
||||
|
||||
return next();
|
||||
};
|
||||
@ -145,7 +147,7 @@ export class CrawlStandAloneServer extends ExpressServer {
|
||||
this.expressRootRouter.use('/',
|
||||
...this.registry.expressMiddlewares,
|
||||
this.makeAssetsServingController(),
|
||||
this.makeIgnoreOPTIONSMiddleware(),
|
||||
this.makeMiscMiddleware(),
|
||||
this.registry.makeShimController('crawl')
|
||||
);
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ process.env['FIREBASE_CONFIG'] ??= JSON.stringify({
|
||||
initializeApp();
|
||||
|
||||
|
||||
import { Logger, CloudFunctionRegistry } from '../shared';
|
||||
import { Logger, CloudFunctionRegistry, AsyncContext } from '../shared';
|
||||
import { AbstractRPCRegistry, OpenAPIManager } from 'civkit/civ-rpc';
|
||||
import { ExpressServer } from 'civkit/civ-rpc/express';
|
||||
import http2 from 'http2';
|
||||
@ -46,6 +46,7 @@ export class SearchStandAloneServer extends ExpressServer {
|
||||
protected globalLogger: Logger,
|
||||
protected registry: CloudFunctionRegistry,
|
||||
protected searcherHost: SearcherHost,
|
||||
protected threadLocal: AsyncContext,
|
||||
) {
|
||||
super(...arguments);
|
||||
|
||||
@ -98,11 +99,12 @@ export class SearchStandAloneServer extends ExpressServer {
|
||||
};
|
||||
}
|
||||
|
||||
makeIgnoreOPTIONSMiddleware() {
|
||||
makeMiscMiddleware() {
|
||||
return (req: Request, res: Response, next: NextFunction) => {
|
||||
if (req.method === 'OPTIONS') {
|
||||
return res.status(200).end();
|
||||
}
|
||||
this.threadLocal.set('ip', req.ip);
|
||||
|
||||
return next();
|
||||
};
|
||||
@ -144,7 +146,7 @@ export class SearchStandAloneServer extends ExpressServer {
|
||||
|
||||
this.expressRootRouter.use('/',
|
||||
...this.registry.expressMiddlewares,
|
||||
this.makeIgnoreOPTIONSMiddleware(),
|
||||
this.makeMiscMiddleware(),
|
||||
this.makeAssetsServingController(),
|
||||
this.registry.makeShimController('search')
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user