Remove search server
This commit is contained in:
parent
a8ab15e49d
commit
cc70428986
|
@ -1,29 +0,0 @@
|
|||
const express = require('express')
|
||||
const npmSearch = require('./npm/search')
|
||||
|
||||
function createSearchServer() {
|
||||
const app = express()
|
||||
|
||||
app.get('/', function(req, res) {
|
||||
const { query, page = 0 } = req.query
|
||||
|
||||
if (!query)
|
||||
return res.status(403).send({ error: 'Missing ?query parameter' })
|
||||
|
||||
npmSearch(query, page).then(
|
||||
function(result) {
|
||||
res.send(result)
|
||||
},
|
||||
function(error) {
|
||||
console.error(error)
|
||||
res
|
||||
.status(500)
|
||||
.send({ error: 'There was an error executing the search' })
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
return app
|
||||
}
|
||||
|
||||
module.exports = createSearchServer
|
|
@ -20,10 +20,12 @@ const PackageBlacklist = require('./PackageBlacklist').blacklist
|
|||
|
||||
function errorHandler(err, req, res, next) {
|
||||
console.error(err.stack)
|
||||
|
||||
res
|
||||
.status(500)
|
||||
.type('text')
|
||||
.send('Internal Server Error')
|
||||
|
||||
next(err)
|
||||
}
|
||||
|
||||
|
@ -54,8 +56,6 @@ function createServer() {
|
|||
)
|
||||
|
||||
if (process.env.NODE_ENV !== 'test') {
|
||||
const createSearchServer = require('./createSearchServer')
|
||||
app.use('/_search', createSearchServer())
|
||||
|
||||
const createStatsServer = require('./createStatsServer')
|
||||
app.use('/_stats', createStatsServer())
|
||||
|
|
|
@ -1,105 +0,0 @@
|
|||
/**
|
||||
* A hand-built index of paths in npm packages that use globals. The index is
|
||||
* not meant to contain *all* the global paths that a given package publishes,
|
||||
* but rather those that are probably most useful for someone who wants to put
|
||||
* a library on a page quickly in development.
|
||||
*
|
||||
* Each entry in the index is keyed by package name and contains a list of
|
||||
* [ versionRange, ...paths ] for that package. The list is traversed in order,
|
||||
* so version ranges that come sooner will match before those that come later.
|
||||
* The range `null` is a catch-all.
|
||||
*/
|
||||
module.exports = {
|
||||
angular: [['>=1.2.27', '/angular.min.js'], [null, '/lib/angular.min.js']],
|
||||
|
||||
'angular-animate': [[null, '/angular-animate.min.js']],
|
||||
|
||||
'angular-cookies': [[null, '/angular-cookies.min.js']],
|
||||
|
||||
'angular-resource': [[null, '/angular-resource.min.js']],
|
||||
|
||||
'angular-sanitize': [[null, '/angular-sanitize.min.js']],
|
||||
|
||||
'angular-ui-bootstrap': [[null, '/dist/ui-bootstrap.js']],
|
||||
|
||||
'animate.css': [[null, '/animate.min.css']],
|
||||
|
||||
'babel-standalone': [[null, '/babel.min.js']],
|
||||
|
||||
backbone: [[null, '/backbone-min.js']],
|
||||
|
||||
bootstrap: [
|
||||
[null, '/dist/css/bootstrap.min.css', '/dist/js/bootstrap.min.js']
|
||||
],
|
||||
|
||||
'bootstrap-sass': [[null, '/assets/javascripts/bootstrap.min.js']],
|
||||
|
||||
bulma: [[null, '/css/bulma.css']],
|
||||
|
||||
'core.js': [[null, '/dist/core.min.js']],
|
||||
|
||||
'create-react-class': [[null, '/create-react-class.min.js']],
|
||||
|
||||
d3: [[null, '/build/d3.min.js']],
|
||||
|
||||
'ember-source': [[null, '/dist/ember.min.js']],
|
||||
|
||||
'foundation-sites': [
|
||||
[null, '/dist/css/foundation.min.css', '/dist/js/foundation.min.js']
|
||||
],
|
||||
|
||||
gsap: [[null, '/TweenMax.js']],
|
||||
|
||||
handlebars: [[null, '/dist/handlebars.min.js']],
|
||||
|
||||
jquery: [[null, '/dist/jquery.min.js']],
|
||||
|
||||
fastclick: [[null, '/lib/fastclick.js']],
|
||||
|
||||
lodash: [['<3', '/dist/lodash.min.js'], [null, '/lodash.min.js']],
|
||||
|
||||
'masonry-layout': [[null, '/dist/masonry.pkgd.min.js']],
|
||||
|
||||
'materialize-css': [[null, '/dist/css/materialize.min.css']],
|
||||
|
||||
'ngx-bootstrap': [[null, '/bundles/ngx-bootstrap.umd.js']],
|
||||
|
||||
react: [
|
||||
['>=16.0.0-alpha.7', '/umd/react.production.min.js'],
|
||||
[null, '/dist/react.min.js']
|
||||
],
|
||||
|
||||
'react-bootstrap': [[null, '/dist/react-bootstrap.min.js']],
|
||||
|
||||
'react-dom': [
|
||||
['>=16.0.0-alpha.7', '/umd/react-dom.production.min.js'],
|
||||
[null, '/dist/react-dom.min.js']
|
||||
],
|
||||
|
||||
'react-router': [
|
||||
['>=4.0.0', '/umd/react-router.min.js'],
|
||||
[null, '/umd/ReactRouter.min.js']
|
||||
],
|
||||
|
||||
redux: [[null, '/dist/redux.min.js']],
|
||||
|
||||
'redux-saga': [[null, '/dist/redux-saga.min.js']],
|
||||
|
||||
'redux-thunk': [[null, '/dist/redux-thunk.min.js']],
|
||||
|
||||
snapsvg: [[null, '/snap.svg-min.js']],
|
||||
|
||||
systemjs: [[null, '/dist/system.js']],
|
||||
|
||||
three: [['<=0.77.0', '/three.min.js'], [null, '/build/three.min.js']],
|
||||
|
||||
underscore: [[null, '/underscore-min.js']],
|
||||
|
||||
vue: [[null, '/dist/vue.min.js']],
|
||||
|
||||
zepto: [[null, '/dist/zepto.min.js']],
|
||||
|
||||
zingchart: [[null, '/client/zingchart.min.js']],
|
||||
|
||||
'zone.js': [[null, '/dist/zone.js']]
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
const semver = require('semver')
|
||||
const assetPathsIndex = require('./assetPathsIndex')
|
||||
|
||||
function getAssetPaths(packageName, version) {
|
||||
const entries = assetPathsIndex[packageName]
|
||||
|
||||
if (entries) {
|
||||
const matchingEntry = entries.find(entry => {
|
||||
const range = entry[0]
|
||||
|
||||
if (range == null || semver.satisfies(version, range)) return entry
|
||||
})
|
||||
|
||||
return matchingEntry.slice(1)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
module.exports = getAssetPaths
|
|
@ -1,83 +0,0 @@
|
|||
const searchIndex = require('./searchIndex')
|
||||
const getAssetPaths = require('./getAssetPaths')
|
||||
|
||||
function enhanceHit(hit) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const assetPaths = getAssetPaths(hit.name, hit.version)
|
||||
|
||||
if (assetPaths) {
|
||||
// TODO: Double check the package metadata to ensure the files
|
||||
// haven't moved from the paths in the index?
|
||||
hit.assets = assetPaths.map(
|
||||
path => `https://unpkg.com/${hit.name}@${hit.version}${path}`
|
||||
)
|
||||
|
||||
resolve(hit)
|
||||
} else {
|
||||
// We don't have any global paths for this package yet. Try
|
||||
// using the "bare" URL.
|
||||
hit.assets = [`https://unpkg.com/${hit.name}@${hit.version}`]
|
||||
|
||||
resolve(hit)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// add concatenated name for more relevance for people spelling without spaces
|
||||
// think: createreactnative instead of create-react-native-app
|
||||
function concat(string) {
|
||||
return string.replace(/[-/@_.]+/g, '')
|
||||
}
|
||||
|
||||
function search(query, page) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const hitsPerPage = 10
|
||||
|
||||
const params = {
|
||||
// typoTolerance: 'min',
|
||||
// optionalFacetFilters: `concatenatedName:${concat(query)}`,
|
||||
facets: ['keywords'],
|
||||
attributesToHighlight: null,
|
||||
attributesToRetrieve: [
|
||||
'description',
|
||||
'githubRepo',
|
||||
'keywords',
|
||||
'license',
|
||||
'name',
|
||||
'owner',
|
||||
'version'
|
||||
],
|
||||
// restrictSearchableAttributes: [
|
||||
// 'name',
|
||||
// 'description',
|
||||
// 'keywords'
|
||||
// ],
|
||||
hitsPerPage,
|
||||
page
|
||||
}
|
||||
|
||||
searchIndex.search(query, params, function(error, value) {
|
||||
if (error) {
|
||||
reject(error)
|
||||
} else {
|
||||
resolve(
|
||||
Promise.all(value.hits.map(enhanceHit)).then(hits => {
|
||||
const totalHits = value.nbHits
|
||||
const totalPages = value.nbPages
|
||||
|
||||
return {
|
||||
query,
|
||||
page,
|
||||
hitsPerPage,
|
||||
totalHits,
|
||||
totalPages,
|
||||
hits
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = search
|
|
@ -1,21 +0,0 @@
|
|||
const algolia = require('algoliasearch')
|
||||
const invariant = require('invariant')
|
||||
|
||||
const AlgoliaNpmSearchAppId = process.env.ALGOLIA_NPM_SEARCH_APP_ID
|
||||
const AlgoliaNpmSearchApiKey = process.env.ALGOLIA_NPM_SEARCH_API_KEY
|
||||
|
||||
invariant(
|
||||
AlgoliaNpmSearchAppId,
|
||||
'Missing $ALGOLIA_NPM_SEARCH_APP_ID environment variable'
|
||||
)
|
||||
|
||||
invariant(
|
||||
AlgoliaNpmSearchApiKey,
|
||||
'Missing $ALGOLIA_NPM_SEARCH_API_KEY environment variable'
|
||||
)
|
||||
|
||||
const index = algolia(AlgoliaNpmSearchAppId, AlgoliaNpmSearchApiKey).initIndex(
|
||||
'npm-search'
|
||||
)
|
||||
|
||||
module.exports = index
|
Loading…
Reference in New Issue