Skip to content

Commit

Permalink
feat(radio-gql): initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardocasares committed Mar 20, 2019
0 parents commit 1a4b81b
Show file tree
Hide file tree
Showing 13 changed files with 3,019 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.git
node_modules
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/carbon
44 changes: 44 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
language: node_js

node_js:
- "lts/*"

cache:
directories:
- "node_modules"

install:
- npm ci

script:
- npm -v
- node -v

deploy:
- provider: script
skip_cleanup: true
script: npm run release
on:
branch: master

- provider: script
skip_cleanup: true
script: npm run deploy:prod
on:
branch: master

- provider: script
skip_cleanup: true
script: npm run deploy:stage
on:
branch: beta

- provider: script
skip_cleanup: true
script: npm run release
on:
branch: beta

notifications:
email:
on_success: never
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM mhart/alpine-node:latest AS build
WORKDIR /app
ADD package*.json /app/
RUN npm ci

FROM mhart/alpine-node:base
COPY --from=build /app .
ADD *.js ./
CMD node bin.js --port 3000
81 changes: 81 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
[![Build Status](https://travis-ci.com/ricardocasares/radio-gql.svg?branch=master)](https://travis-ci.com/ricardocasares/radio-gql)
![Docker Pulls](https://img.shields.io/docker/pulls/ricardocasares/radio-gql.svg)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)

# GraphQL API for http://www.radio-browser.info

Check the [playground](https://radio-gql.analogic.al)

[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/ricardocasares/radio-gql)

## Sample query

```gql
{
stations(query: "Electro") {
url
name
tags
}
}
```

## Stack

-[now](https://now.sh)
- docker
- [polka](https://github.com/lukeed/polka)
- [express-graphql](https://github.com/graphql/express-graphql)
- [radio-browser](http://www.radio-browser.info)

## Running the npm package

```bash
npm i -g radio-gql
radio-gql --port 3000
```

## Running the docker image

```bash
docker run -p 3000:3000 ricardocasares/radio-gql
```

### Build from scratch

Clone the repository and inside the root folder run:

```bash
docker build . -t radio-gql
docker run -p 3000:3000 radio-gql
```

You can now visit the playground at [http://localhost:3000](http://localhost:3000)

## Contributing

Feel free to open an issue, pull requests are preferred.

**IMPORTANT** Make sure you always create new branches from `beta`.

### Automated versioning

We use `semantic-release` to automate the versioning process, make sure you follow the [commit message convention explained here](https://github.com/semantic-release/semantic-release#commit-message-format).

**HEADS UP:** If you are not sure how write a commit message, make your changes in your feature branch and run `npm run commit` and follow the assistant.

### Releases

#### Beta

Create a feature branch and make a pull-request to `beta` branch.
Once its merged, you can try and install the package using `@beta` dist tag on `npm`.

```bash
npm i -g radio-gql@beta
```

#### Production

Create a new pull-request from `beta` to `master` branch.
Once it gets merged, the final version will be released using `@latest` dist tag on `npm`.
14 changes: 14 additions & 0 deletions bin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env node
const server = require("./");
const port = parseInt(process.argv.slice(3), 10);

const log = msg => err => {
if (err) throw new Error(err);
console.log(msg);
};

if (!port || isNaN(port)) {
throw new Error("You must provide --port NUMBER");
}

server.listen(port, log(`> Listening on http://localhost:${port}/`));
22 changes: 22 additions & 0 deletions client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const fetch = require("isomorphic-unfetch");

const URL = "http://www.radio-browser.info/webservice";
const BY_NAME = "/json/stations/byname";
const SERVICE = `${URL}/${BY_NAME}`;
const cfg = {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
"User-Agent": "bemba/radio-gql"
},
body: JSON.stringify({ order: "votes", reverse: "true", limit: 50 })
};

async function search(name) {
return fetch(`${SERVICE}/${name}`, cfg).then(res => res.json());
}

module.exports = {
search
};
15 changes: 15 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const cors = require("cors");
const polka = require("polka");
const graphql = require("express-graphql");
const schema = require("./schema");
const server = polka()
.use(cors())
.use(
"/",
graphql({
schema,
graphiql: true
})
);

module.exports = server;
9 changes: 9 additions & 0 deletions now.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"version": 1,
"name": "radio-gql",
"type": "docker",
"features": {
"cloud": "v2"
},
"alias": ["radio-gql.analogic.al"]
}
Loading

0 comments on commit 1a4b81b

Please sign in to comment.