Spaces:
Build error
Build error
fix(stand-alone-server): set ip to local context
Browse files
backend/functions/src/services/serper-search.ts
CHANGED
|
@@ -53,13 +53,13 @@ export class SerperSearchService extends AsyncService {
|
|
| 53 |
if (locationChunks.length) {
|
| 54 |
query.location ??= locationChunks.join(', ');
|
| 55 |
}
|
| 56 |
-
|
| 57 |
}
|
| 58 |
|
| 59 |
let maxTries = 3;
|
| 60 |
|
| 61 |
while (maxTries--) {
|
| 62 |
try {
|
|
|
|
| 63 |
const r = await this.serperSearchHTTP.webSearch(query);
|
| 64 |
|
| 65 |
return r.parsed;
|
|
|
|
| 53 |
if (locationChunks.length) {
|
| 54 |
query.location ??= locationChunks.join(', ');
|
| 55 |
}
|
|
|
|
| 56 |
}
|
| 57 |
|
| 58 |
let maxTries = 3;
|
| 59 |
|
| 60 |
while (maxTries--) {
|
| 61 |
try {
|
| 62 |
+
this.logger.debug(`Doing external search`, query);
|
| 63 |
const r = await this.serperSearchHTTP.webSearch(query);
|
| 64 |
|
| 65 |
return r.parsed;
|
backend/functions/src/stand-alone/crawl.ts
CHANGED
|
@@ -11,7 +11,7 @@ process.env['FIREBASE_CONFIG'] ??= JSON.stringify({
|
|
| 11 |
initializeApp();
|
| 12 |
|
| 13 |
|
| 14 |
-
import { Logger, CloudFunctionRegistry } from '../shared';
|
| 15 |
import { AbstractRPCRegistry, OpenAPIManager } from 'civkit/civ-rpc';
|
| 16 |
import { ExpressServer } from 'civkit/civ-rpc/express';
|
| 17 |
import http2 from 'http2';
|
|
@@ -46,6 +46,7 @@ export class CrawlStandAloneServer extends ExpressServer {
|
|
| 46 |
protected globalLogger: Logger,
|
| 47 |
protected registry: CloudFunctionRegistry,
|
| 48 |
protected crawlerHost: CrawlerHost,
|
|
|
|
| 49 |
) {
|
| 50 |
super(...arguments);
|
| 51 |
|
|
@@ -98,11 +99,12 @@ export class CrawlStandAloneServer extends ExpressServer {
|
|
| 98 |
};
|
| 99 |
}
|
| 100 |
|
| 101 |
-
|
| 102 |
return (req: Request, res: Response, next: NextFunction) => {
|
| 103 |
if (req.method === 'OPTIONS') {
|
| 104 |
return res.status(200).end();
|
| 105 |
}
|
|
|
|
| 106 |
|
| 107 |
return next();
|
| 108 |
};
|
|
@@ -145,7 +147,7 @@ export class CrawlStandAloneServer extends ExpressServer {
|
|
| 145 |
this.expressRootRouter.use('/',
|
| 146 |
...this.registry.expressMiddlewares,
|
| 147 |
this.makeAssetsServingController(),
|
| 148 |
-
this.
|
| 149 |
this.registry.makeShimController('crawl')
|
| 150 |
);
|
| 151 |
}
|
|
|
|
| 11 |
initializeApp();
|
| 12 |
|
| 13 |
|
| 14 |
+
import { Logger, CloudFunctionRegistry, AsyncContext } from '../shared';
|
| 15 |
import { AbstractRPCRegistry, OpenAPIManager } from 'civkit/civ-rpc';
|
| 16 |
import { ExpressServer } from 'civkit/civ-rpc/express';
|
| 17 |
import http2 from 'http2';
|
|
|
|
| 46 |
protected globalLogger: Logger,
|
| 47 |
protected registry: CloudFunctionRegistry,
|
| 48 |
protected crawlerHost: CrawlerHost,
|
| 49 |
+
protected threadLocal: AsyncContext,
|
| 50 |
) {
|
| 51 |
super(...arguments);
|
| 52 |
|
|
|
|
| 99 |
};
|
| 100 |
}
|
| 101 |
|
| 102 |
+
makeMiscMiddleware() {
|
| 103 |
return (req: Request, res: Response, next: NextFunction) => {
|
| 104 |
if (req.method === 'OPTIONS') {
|
| 105 |
return res.status(200).end();
|
| 106 |
}
|
| 107 |
+
this.threadLocal.set('ip', req.ip);
|
| 108 |
|
| 109 |
return next();
|
| 110 |
};
|
|
|
|
| 147 |
this.expressRootRouter.use('/',
|
| 148 |
...this.registry.expressMiddlewares,
|
| 149 |
this.makeAssetsServingController(),
|
| 150 |
+
this.makeMiscMiddleware(),
|
| 151 |
this.registry.makeShimController('crawl')
|
| 152 |
);
|
| 153 |
}
|
backend/functions/src/stand-alone/search.ts
CHANGED
|
@@ -11,7 +11,7 @@ process.env['FIREBASE_CONFIG'] ??= JSON.stringify({
|
|
| 11 |
initializeApp();
|
| 12 |
|
| 13 |
|
| 14 |
-
import { Logger, CloudFunctionRegistry } from '../shared';
|
| 15 |
import { AbstractRPCRegistry, OpenAPIManager } from 'civkit/civ-rpc';
|
| 16 |
import { ExpressServer } from 'civkit/civ-rpc/express';
|
| 17 |
import http2 from 'http2';
|
|
@@ -46,6 +46,7 @@ export class SearchStandAloneServer extends ExpressServer {
|
|
| 46 |
protected globalLogger: Logger,
|
| 47 |
protected registry: CloudFunctionRegistry,
|
| 48 |
protected searcherHost: SearcherHost,
|
|
|
|
| 49 |
) {
|
| 50 |
super(...arguments);
|
| 51 |
|
|
@@ -98,11 +99,12 @@ export class SearchStandAloneServer extends ExpressServer {
|
|
| 98 |
};
|
| 99 |
}
|
| 100 |
|
| 101 |
-
|
| 102 |
return (req: Request, res: Response, next: NextFunction) => {
|
| 103 |
if (req.method === 'OPTIONS') {
|
| 104 |
return res.status(200).end();
|
| 105 |
}
|
|
|
|
| 106 |
|
| 107 |
return next();
|
| 108 |
};
|
|
@@ -144,7 +146,7 @@ export class SearchStandAloneServer extends ExpressServer {
|
|
| 144 |
|
| 145 |
this.expressRootRouter.use('/',
|
| 146 |
...this.registry.expressMiddlewares,
|
| 147 |
-
this.
|
| 148 |
this.makeAssetsServingController(),
|
| 149 |
this.registry.makeShimController('search')
|
| 150 |
);
|
|
|
|
| 11 |
initializeApp();
|
| 12 |
|
| 13 |
|
| 14 |
+
import { Logger, CloudFunctionRegistry, AsyncContext } from '../shared';
|
| 15 |
import { AbstractRPCRegistry, OpenAPIManager } from 'civkit/civ-rpc';
|
| 16 |
import { ExpressServer } from 'civkit/civ-rpc/express';
|
| 17 |
import http2 from 'http2';
|
|
|
|
| 46 |
protected globalLogger: Logger,
|
| 47 |
protected registry: CloudFunctionRegistry,
|
| 48 |
protected searcherHost: SearcherHost,
|
| 49 |
+
protected threadLocal: AsyncContext,
|
| 50 |
) {
|
| 51 |
super(...arguments);
|
| 52 |
|
|
|
|
| 99 |
};
|
| 100 |
}
|
| 101 |
|
| 102 |
+
makeMiscMiddleware() {
|
| 103 |
return (req: Request, res: Response, next: NextFunction) => {
|
| 104 |
if (req.method === 'OPTIONS') {
|
| 105 |
return res.status(200).end();
|
| 106 |
}
|
| 107 |
+
this.threadLocal.set('ip', req.ip);
|
| 108 |
|
| 109 |
return next();
|
| 110 |
};
|
|
|
|
| 146 |
|
| 147 |
this.expressRootRouter.use('/',
|
| 148 |
...this.registry.expressMiddlewares,
|
| 149 |
+
this.makeMiscMiddleware(),
|
| 150 |
this.makeAssetsServingController(),
|
| 151 |
this.registry.makeShimController('search')
|
| 152 |
);
|