@@ -1,3 +1 @@
|
||||
module.exports = {
|
||||
extends: [require.resolve('@backstage/cli/config/eslint.backend')],
|
||||
};
|
||||
module.exports = require('@backstage/cli/config/eslint-factory')(__dirname);
|
||||
|
||||
@@ -32,7 +32,8 @@ When you have your `packages/backend/src/plugins/search.ts` file ready to make m
|
||||
```ts
|
||||
indexBuilder.addCollator({
|
||||
defaultRefreshIntervalSeconds: 600,
|
||||
factory: StackOverflowQuestionsCollatorFactory.fromConfig(config, {
|
||||
factory: StackOverflowQuestionsCollatorFactory.fromConfig(env.config, {
|
||||
logger: env.logger,
|
||||
requestParams: {
|
||||
tagged: ['backstage'],
|
||||
site: 'stackoverflow',
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
/// <reference types="node" />
|
||||
|
||||
import { Config } from '@backstage/config';
|
||||
import { DocumentCollatorFactory } from '@backstage/search-common';
|
||||
import { IndexableDocument } from '@backstage/search-common';
|
||||
import { DocumentCollatorFactory } from '@backstage/plugin-search-common';
|
||||
import { IndexableDocument } from '@backstage/plugin-search-common';
|
||||
import { Logger } from 'winston';
|
||||
import { Readable } from 'stream';
|
||||
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2022 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export interface Config {
|
||||
/**
|
||||
* Configuration options for the stack overflow plugin
|
||||
*/
|
||||
stackoverflow: {
|
||||
/**
|
||||
* The base url of the Stack Overflow API used for the plugin
|
||||
* @visibility backend
|
||||
*/
|
||||
baseUrl: string;
|
||||
};
|
||||
}
|
||||
@@ -33,13 +33,14 @@
|
||||
"clean": "backstage-cli package clean"
|
||||
},
|
||||
"dependencies": {
|
||||
"@backstage/search-common": "^0.3.1",
|
||||
"@backstage/config": "^0.1.15",
|
||||
"qs": "^6.10.3",
|
||||
"@backstage/plugin-search-common": "^0.3.3-next.0",
|
||||
"@backstage/config": "^1.0.0",
|
||||
"qs": "^6.9.4",
|
||||
"cross-fetch": "^3.1.5",
|
||||
"winston": "^3.6.0"
|
||||
"winston": "^3.2.1"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
"dist",
|
||||
"config"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
import {
|
||||
IndexableDocument,
|
||||
DocumentCollatorFactory,
|
||||
} from '@backstage/search-common';
|
||||
} from '@backstage/plugin-search-common';
|
||||
import { Config } from '@backstage/config';
|
||||
import { Readable } from 'stream';
|
||||
import fetch from 'cross-fetch';
|
||||
@@ -77,7 +77,9 @@ export class StackOverflowQuestionsCollatorFactory
|
||||
config: Config,
|
||||
options: StackOverflowQuestionsCollatorFactoryOptions,
|
||||
) {
|
||||
const baseUrl = config.getString('stackoverflow.baseUrl');
|
||||
const baseUrl =
|
||||
config.getOptionalString('stackoverflow.baseUrl') ||
|
||||
'https://api.stackexchange.com/2.2';
|
||||
return new StackOverflowQuestionsCollatorFactory({ ...options, baseUrl });
|
||||
}
|
||||
|
||||
@@ -91,9 +93,11 @@ export class StackOverflowQuestionsCollatorFactory
|
||||
`No stackoverflow.baseUrl configured in your app-config.yaml`,
|
||||
);
|
||||
}
|
||||
const params = this.requestParams
|
||||
? `?${qs.stringify(this.requestParams, { arrayFormat: 'comma' })}`
|
||||
: '';
|
||||
const params = qs.stringify(this.requestParams, {
|
||||
arrayFormat: 'comma',
|
||||
addQueryPrefix: true,
|
||||
});
|
||||
|
||||
const res = await fetch(`${this.baseUrl}/questions${params}`);
|
||||
const data = await res.json();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user