Skip to content
This repository has been archived by the owner on Nov 5, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' into greenkeeper/initial
Browse files Browse the repository at this point in the history
  • Loading branch information
zrrrzzt committed May 3, 2017
2 parents 34341c0 + 5696924 commit 1421aae
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ node_js:
- "7"
after_success:
- npm run coveralls
- test $TRAVIS_BRANCH = "master" && npm i -g now && now -t=$NOW_TOKEN -E --npm && now -t=$NOW_TOKEN alias
- test $TRAVIS_BRANCH = "master" && npm i -g now && now -t=$NOW_TOKEN --npm && now -t=$NOW_TOKEN alias
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#
###########################################################

# Setting the base to nodejs 7.7.1
FROM node:7.7.1-alpine
# Setting the base to nodejs 7.7.3
FROM node:7.7.3-alpine

# Maintainer
MAINTAINER Jonas Enge
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

# minelev-buddy-dummy

A dummy version of the buddy api for MinElev demoes

# API

It supports the same calls as [buddy-minelev-api](https://github.com/telemark/buddy-minelev-api)

[MIT](LICENSE)

![alt text](https://robots.kebabstudios.party/minelev-buddy-dummy.png "Robohash image of minelev-buddy-dummy")
![Robohash image of minelev-buddy-dummy](https://robots.kebabstudios.party/minelev-buddy-dummy.png "Robohash image of minelev-buddy-dummy")
5 changes: 0 additions & 5 deletions data/contactClasses.json

This file was deleted.

6 changes: 3 additions & 3 deletions data/contactTeachers.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"username": "jantejante",
"groupId": "KRAVS:3REA",
"mail": "jante@t-fk.no"
"username": "riemann",
"groupId": "BAMVS:3ST",
"mail": "riemann@minelev.no"
}
]
1 change: 1 addition & 0 deletions data/gauss/contactClasses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
1 change: 1 addition & 0 deletions data/gauss/gauss.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is the gauss directory
File renamed without changes.
5 changes: 5 additions & 0 deletions data/riemann/contactClasses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
{
"Id": "BAMVS:3ST"
}
]
1 change: 1 addition & 0 deletions data/riemann/riemann.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is the riemann directory
27 changes: 27 additions & 0 deletions data/riemann/student.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[
{
"firstName": "Helge Grim",
"middleName": null,
"lastName": "Grim",
"fullName": "Helge Grim",
"personalIdNumber": "02059711111",
"mobilePhone": "+4798888888",
"mail": "helgeg@hotmail.com",
"userName": "0205helgeg",
"contactTeacher": true,
"unitId": "BAMVS",
"unitName": "Bamble vgs. avd. Grasmyr",
"organizationNumber": "NO974568098",
"mainGroupName": "BAMVS:3ST",
"groups": [
{
"id": "BAMVS:3ST/151FSP5098",
"description": "Spansk I+II",
"unitId": "BAMVS",
"unitName": "Bamble vgs. avd. Grasmyr",
"organizationNumber": "NO974568098",
"contactTeacher": true
}
]
}
]
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
'use strict'

const readFileSync = require('fs').readFileSync
const marked = require('marked')
const { send } = require('micro')
const { parse } = require('url')
const actionHandler = require('./lib/action-handler')
const pkg = require('./package.json')

module.exports = async (request, response) => {
const { pathname } = await parse(request.url, true)
if (pathname === '/favicon.ico') {
send(response, 404)
} else if (pathname === '/ping') {
send(response, 200, { ping: 'pong' })
send(response, 200, { ping: 'pong', 'name': pkg.name, version: pkg.version })
} else if (pathname === '/') {
const readme = readFileSync('./README.md', 'utf-8')
const html = marked(readme)
send(response, 200, html)
} else {
send(response, 200, actionHandler(request))
}
Expand Down
18 changes: 9 additions & 9 deletions lib/action-handler.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
'use strict'

const match = require('micro-match')
const student = require('../data/student.json')
const students = require('../data/students.json')
const search = require('../data/search.json')
const contactTeachers = require('../data/contactTeachers.json')
const contactClasses = require('../data/contactClasses.json')

module.exports = request => {
switch (true) {
case /students/.test(request.url):
const { id } = match('/users/:user/students/:id', request.url) || false

if (id) {
return student
} else {
return students
let { user, id } = match('/users/:user/students/:id', request.url) || false
if (!['gauss', 'riemann'].includes(user)) {
user = 'riemann'
}
return id ? require(`../data/${user}/student.json`) : students

case /search/.test(request.url):
return search
Expand All @@ -25,7 +21,11 @@ module.exports = request => {
return contactTeachers

case /contactClasses/.test(request.url):
return contactClasses
let { userid } = match('/users/:userid/contactClasses', request.url) || false
if (!['gauss', 'riemann'].includes(userid)) {
userid = 'riemann'
}
return require(`../data/${userid}/contactClasses.json`)

default:
return { error: 'Invalid method' }
Expand Down
25 changes: 14 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "minelev-buddy-dummy",
"description": "Dummy data for minelev buddy",
"version": "1.0.0",
"version": "1.0.1",
"license": "MIT",
"private": true,
"author": {
Expand All @@ -18,7 +18,7 @@
],
"main": "index.js",
"engines": {
"node": ">=7.7.1"
"node": ">=7.7.3"
},
"scripts": {
"test": "standard && nsp check && ava",
Expand All @@ -27,7 +27,7 @@
"coveralls": "nyc ava && nyc report --reporter=lcov && cat coverage/lcov.info | coveralls",
"standard-fix": "standard --fix",
"start": "micro",
"now-deploy": "npm test && now --npm -E && now alias"
"now-deploy": "npm test && now --npm && now alias"
},
"keywords": [
"microservice",
Expand All @@ -41,22 +41,25 @@
"bugs": {
"url": "https://github.com/telemark/minelev-buddy-dummy/issues"
},
"homepage": "https://github.com/telemark/minelev-buddy-dummy",
"now": {
"alias": "",
"alias": "dummy.buddy.minelev.t-fk.win",
"env": {
"NODE_ENV": "production"
}
},
"devDependencies": {
"ava": "0.18.2",
"coveralls": "2.12.0",
"ava": "0.19.1",
"axios": "0.16.1",
"coveralls": "2.13.1",
"nsp": "2.6.3",
"nyc": "10.1.2",
"standard": "9.0.1",
"test-listen": "1.0.1"
"nyc": "10.3.0",
"standard": "10.0.2",
"test-listen": "1.0.2"
},
"dependencies": {
"micro": "7.1.0",
"marked": "0.3.6",
"micro": "7.3.2",
"micro-match": "0.1.2"
}
}
}
18 changes: 18 additions & 0 deletions test/routes/get-frontpage-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict'

const test = require('ava')
const listen = require('test-listen')
const axios = require('axios')
const micro = require('micro')
const srv = require('../../index')

const getUrl = fn => {
const srv = micro(fn)
return listen(srv)
}

test('it returns README as frontpage', async t => {
const url = await getUrl(srv)
const result = await axios.get(url)
t.true(result.data.includes('MIT'), 'frontpage ok')
})

0 comments on commit 1421aae

Please sign in to comment.