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