Skip to content

Commit

Permalink
switch to proxy for api
Browse files Browse the repository at this point in the history
  • Loading branch information
hsheth2 committed May 25, 2020
1 parent abf2f15 commit 7706507
Show file tree
Hide file tree
Showing 7 changed files with 1,364 additions and 8 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ppa-stats-web

TODO
- add search button
- match query with hash router to allow for direct linking
- cut out backend API and query launchpad directly

## References
- https://launchpad.net/+apidoc/1.0.html
Expand Down
21 changes: 14 additions & 7 deletions frontend/src/components/PackageSelection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ export default {
return Promise.resolve([]);
}
return this.$http
.get(`/api/owner/${ppaOwner}/list_ppas`)
.get(`/lp-api/1.0/~${ppaOwner}/ppas`)
.then((response) => {
console.log(response.data);
return response.data;
const ppas = response.data.entries.map((entry) => entry.name);
console.log(ppas);
return ppas;
});
}, 500),
watch: ['ppaOwner'],
Expand All @@ -99,10 +100,16 @@ export default {
return Promise.resolve([]);
}
return this.$http
.get(`/api/owner/${ppaOwner}/ppa/${ppaName}/list_packages`)
.then(({ data }) => {
console.log(data);
return data;
.get(
`/lp-api/1.0/~${ppaOwner}/+archive/${ppaName}?ws.op=getPublishedBinaries`
)
.then((response) => {
const binaries = response.data.entries;
const packages = new Set(
binaries.map((binary) => binary.binary_package_name)
);
console.log(packages);
return [...packages];
});
}, 500),
watch: ['ppaOwner', 'ppaName'],
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import Buefy from 'buefy';
import 'buefy/dist/buefy.css';

Vue.use(Buefy);
Vue.use(VueAxios, axios);
Vue.use(
VueAxios,
axios.create({
baseURL: '/',
})
);
Vue.use(AsyncComputed);
Vue.config.productionTip = false;

Expand Down
111 changes: 111 additions & 0 deletions lp-proxy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@

# Created by https://www.gitignore.io/api/node
# Edit at https://www.gitignore.io/?templates=node

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# rollup.js default build output
dist/

# Uncomment the public line if your project uses Gatsby
# https://nextjs.org/blog/next-9-1#public-directory-support
# https://create-react-app.dev/docs/using-the-public-folder/#docsNav
# public

# Storybook build outputs
.out
.storybook-out

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# Temporary folders
tmp/
temp/

# End of https://www.gitignore.io/api/node
13 changes: 13 additions & 0 deletions lp-proxy/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const express = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');

const app = express();

app.use('/lp-api', createProxyMiddleware({
changeOrigin: true,
target:'https://api.launchpad.net/',
pathRewrite: {
'^/lp-api': '/', // rewrite path
},
}));
app.listen(8000);
9 changes: 9 additions & 0 deletions lp-proxy/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"dependencies": {
"express": "^4.17.1",
"http-proxy-middleware": "^1.0.4"
},
"devDependencies": {
"nodemon": "^2.0.4"
}
}
Loading

0 comments on commit 7706507

Please sign in to comment.