-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (30 loc) · 1.17 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const express = require('express')
const axios = require('axios')
const app = new express()
const port = 3000
async function fetchdata(url) {
const fetch = await axios.get(url)
const data = fetch.data
return Promise.resolve(data)
}
app.get('/', (req, res) => {
res.setHeader('Cache-Control', 's-max-age=1, stale-while-revalidate');
res.redirect(`https://flightpkg.js.org`)
})
app.get('/js', (req, res) => {
res.setHeader('Content-Type', 'text/json');
res.setHeader('Cache-Control', 's-max-age=1, stale-while-revalidate');
fetchdata('https://registry.yarnpkg.com').then(r => res.send(r))
})
app.get('/js/:pkg', (req, res) => {
res.setHeader('Content-Type', 'text/json');
res.setHeader('Cache-Control', 's-max-age=1, stale-while-revalidate');
fetchdata(`https://registry.yarnpkg.com/${req.params.pkg}`).then(r => res.send(r))
})
app.get('/js/:name/-/:name-:version.tgz', (req, res) => {
res.setHeader('Cache-Control', 's-max-age=1, stale-while-revalidate');
res.redirect(`https://registry.yarnpkg.com/${req.params.name}/-/${req.params.name}-${req.params.version}.tgz`)
})
app.listen(port, () => {
console.log(`Registry started on ${port}`)
})