Skip to content

Commit c5dcfbd

Browse files
committed
Initial code commit
1 parent 548a5ec commit c5dcfbd

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM node:7.9-alpine
2+
3+
ADD https://github.com/alexellis/faas/releases/download/v0.3-alpha/fwatchdog /usr/bin
4+
RUN chmod +x /usr/bin/fwatchdog
5+
6+
WORKDIR /app
7+
ADD package.json .
8+
ADD index.js .
9+
10+
RUN npm i
11+
12+
ENV fprocess="node /app/index.js"
13+
CMD ["fwatchdog"]

index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const request = require('request')
2+
const getStdin = require('get-stdin')
3+
4+
process.stdin.setEncoding('utf8')
5+
6+
getStdin().then(url => {
7+
url = url.trim()
8+
request.post('http://subr.pw/api/shorten', {
9+
form: { url: url }
10+
}, function(err, httpResponse, body) {
11+
body = JSON.parse(body)
12+
13+
if (err) {
14+
console.log(err)
15+
} else {
16+
if (!body.status) {
17+
console.log(body.message)
18+
} else {
19+
console.log(body.shortlink)
20+
}
21+
}
22+
})
23+
})

package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "faas-node-url-shortener",
3+
"version": "0.0.1",
4+
"description": "A FaaS function to generate shortened URLs via an external service",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "[email protected]/developius/faas-node-url-shortener"
12+
},
13+
"author": "Finnian Anderson <finnian.io>",
14+
"license": "MIT",
15+
"dependencies": {
16+
"get-stdin": "^5.0.1",
17+
"request": "^2.81.0"
18+
}
19+
}

0 commit comments

Comments
 (0)