feat: add Electron hosted headers redirect (#2522)
* feat: add Electron hosted headers redirect * style: prettier * test: add tests
This commit is contained in:
Родитель
14b673833e
Коммит
01033c465c
|
@ -0,0 +1,7 @@
|
|||
const DIST_URL = 'https://gh-contractor-zcbenz.s3.amazonaws.com/atom-shell/dist'
|
||||
|
||||
module.exports = (req, res, next) => {
|
||||
const url = req.params[0]
|
||||
if (url === []) return next()
|
||||
return res.redirect(`${DIST_URL}/${url}`)
|
||||
}
|
|
@ -58,7 +58,7 @@ app.use(requestLanguage({
|
|||
languages: Object.keys(i18n.locales),
|
||||
cookie: {
|
||||
name: 'language',
|
||||
options: {maxAge: 30 * 24 * 60 * 60 * 1000},
|
||||
options: { maxAge: 30 * 24 * 60 * 60 * 1000 },
|
||||
url: '/languages/{language}'
|
||||
}
|
||||
}))
|
||||
|
@ -111,6 +111,7 @@ app.get('/userland', routes.userland.index)
|
|||
app.get('/userland/*', routes.userland.show)
|
||||
app.use('/crowdin', routes.languages.proxy)
|
||||
app.use('/donors', routes.donors)
|
||||
app.use('/headers/*', routes.headers)
|
||||
app.get('/search/:searchIn*?*', (req, res) => res.redirect(req.query.q ? `/?query=${req.query.q}` : `/`))
|
||||
|
||||
// Generic 404 handler
|
||||
|
|
|
@ -655,6 +655,18 @@ describe('electronjs.org', () => {
|
|||
res.headers['content-type'].should.equal('application/javascript; charset=UTF-8')
|
||||
})
|
||||
|
||||
describe('node headers', () => {
|
||||
it('redirects valid to S3 Bucket', async () => {
|
||||
let res = await supertest(app).get(`/headers/v3.1.6/iojs-3.1.6.tgz.tz`)
|
||||
res.statusCode.should.equal(302)
|
||||
})
|
||||
|
||||
it('show 404 to invalid', async () => {
|
||||
let res = await supertest(app).get(`/headers`)
|
||||
res.statusCode.should.equal(404)
|
||||
})
|
||||
})
|
||||
|
||||
describe('search redirects', () => {
|
||||
it('redirect /search/package to home page search', async () => {
|
||||
const res = await supertest(app).get('/search/npmPackages?q=@siberianmh/cosmos')
|
||||
|
|
Загрузка…
Ссылка в новой задаче