Skip to content

Commit

Permalink
Create custom got clients to set user agent
Browse files Browse the repository at this point in the history
  • Loading branch information
tusbar committed Oct 11, 2018
1 parent f40d150 commit 7f6088a
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/api/middlewares/thumbnail-proxy.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const {join} = require('path')
const got = require('got')
const fileType = require('file-type')
const fresh = require('fresh')
const cacheControl = require('@tusbar/cache-control')

const got = require('../../got')

const defaultThumbnailPath = join(__dirname, '../../../france/img/unavailable-thumbnail.png')

const ACCEPTED_MIME_TYPES = [
Expand Down
2 changes: 1 addition & 1 deletion lib/api/routes/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ const {createWriteStream} = require('fs')
const {join} = require('path')
const {Router} = require('express')
const unzipper = require('unzipper')
const got = require('got')
const pump = require('pump')

const got = require('../../got')
const {getLink} = require('../../services/link-proxy')
const {createTempDirectory} = require('../../utils/tempfile')
const ogr2ogr = require('../../extract/ogr2ogr')
Expand Down
9 changes: 9 additions & 0 deletions lib/got.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const got = require('got')

const pkg = require('../package.json')

module.exports = got.extend({
headers: {
'user-agent': `geoplatform/${pkg.version} (+https://geo.data.gouv.fr)`
}
})
2 changes: 1 addition & 1 deletion lib/services/link-proxy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const got = require('got')
const got = require('../got')

const {LINK_PROXY_URL} = process.env

Expand Down
2 changes: 1 addition & 1 deletion plugins/publish-to-udata/geogw.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const got = require('got')
const got = require('./got')

const ROOT_URL = process.env.GEOGW_URL + '/api/geogw'
const TOKEN = process.env.GEOGW_TOKEN
Expand Down
7 changes: 7 additions & 0 deletions plugins/publish-to-udata/got.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const got = require('got')

module.exports = got.extend({
headers: {
'user-agent': 'geoplatform/udata-publisher/v1.0.0 (+https://geo.data.gouv.fr)'
}
})
3 changes: 2 additions & 1 deletion plugins/publish-to-udata/udata-proxy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const {Router} = require('express')
const got = require('got')

const got = require('./got')

const ALLOWED_METHODS = ['GET', 'HEAD', 'POST', 'PUT', 'DELETE']
const baseUrl = process.env.DATAGOUV_URL + '/api'
Expand Down
2 changes: 1 addition & 1 deletion plugins/publish-to-udata/udata.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const got = require('got')
const got = require('./got')

const {DATAGOUV_URL, UDATA_PUBLICATION_USER_API_KEY} = process.env

Expand Down

0 comments on commit 7f6088a

Please sign in to comment.