Skip to content

Commit 76b7df9

Browse files
committed
🚡 Add all the things and all the work.
0 parents  commit 76b7df9

File tree

184 files changed

+20462
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

184 files changed

+20462
-0
lines changed

.gitignore

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
6+
# Runtime data
7+
pids
8+
*.pid
9+
*.seed
10+
*.pid.lock
11+
12+
# Directory for instrumented libs generated by jscoverage/JSCover
13+
lib-cov
14+
15+
# Coverage directory used by tools like istanbul
16+
coverage
17+
18+
# nyc test coverage
19+
.nyc_output
20+
21+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
22+
.grunt
23+
24+
# node-waf configuration
25+
.lock-wscript
26+
27+
# Compiled binary addons (http://nodejs.org/api/addons.html)
28+
build/Release
29+
30+
# Dependency directories
31+
node_modules
32+
jspm_packages
33+
34+
# Optional npm cache directory
35+
.npm
36+
37+
# Optional eslint cache
38+
.eslintcache
39+
40+
# Optional REPL history
41+
.node_repl_history
42+
43+
# Output of 'npm pack'
44+
*.tgz
45+
46+
# Yarn Integrity file
47+
.yarn-integrity

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.0.0

.travis.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
language: node_js
2+
cache: yarn
3+
node_js:
4+
- '6'
5+
- '7'
6+
before_install:
7+
notifications:
8+
email: false
9+
slack:
10+
secure: Q2NlerQC8kgzjkD3gnMFs4VPJ35UMZ8tG6tj/PAHCK4U0iPBJ2Um6WxEa9JvvFe2eXiAIZhq2ZWhfU2cPh/fOYIQYNxGeXFJ8SfnXIJiCzEWCzFtNvRQt1scjukXNPxnvvvT/xP/hfmc9/7EnwlgAQoEQ+1SlMjKIc71g3qzvSw=

conferences/.dev

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
exports port=4000
2+
exports host=localhost

conferences/.dockerignore

Whitespace-only changes.

conferences/.editorconfig

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true

conferences/.gitignore

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
6+
# Runtime data
7+
pids
8+
*.pid
9+
*.seed
10+
*.pid.lock
11+
12+
# Directory for instrumented libs generated by jscoverage/JSCover
13+
lib-cov
14+
15+
# Coverage directory used by tools like istanbul
16+
coverage
17+
18+
# nyc test coverage
19+
.nyc_output
20+
21+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
22+
.grunt
23+
24+
# node-waf configuration
25+
.lock-wscript
26+
27+
# Compiled binary addons (http://nodejs.org/api/addons.html)
28+
build/Release
29+
30+
# Dependency directories
31+
node_modules
32+
jspm_packages
33+
34+
# Optional npm cache directory
35+
.npm
36+
37+
# Optional eslint cache
38+
.eslintcache
39+
40+
# Optional REPL history
41+
.node_repl_history
42+
43+
# Output of 'npm pack'
44+
*.tgz

conferences/.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.1.0

conferences/.prod

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
exports port=4000
2+
exports host=0.0.0.0

conferences/.test

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
exports port=0
2+
exports host=localhost

conferences/Dockerfile

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM node:7
2+
3+
ENV appDir /var/www/app/conferences
4+
ENV NODE_ENV prod
5+
ENV NODE_PATH .
6+
7+
RUN mkdir -p ${appDir}
8+
RUN curl -o- -L https://yarnpkg.com/install.sh | bash
9+
10+
WORKDIR ${appDir}
11+
12+
COPY package.json ${appDir}
13+
COPY yarn.lock ${appDir}
14+
15+
RUN $HOME/.yarn/bin/yarn install
16+
17+
COPY . ${appDir}
18+
19+
EXPOSE 4000
20+
21+
CMD ["node", "server.js"]

conferences/envs.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const env = process.env.NODE_ENV
2+
const production = 'prod'
3+
const development = 'dev'
4+
5+
function isProduction() {
6+
return env === production
7+
}
8+
9+
exports.default = {
10+
env,
11+
production,
12+
development
13+
}
14+
15+
exports.isProduction = isProduction
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const uuid = require('node-uuid')
2+
const faker = require('faker')
3+
4+
function generate() {
5+
return {
6+
id: uuid.v4(),
7+
name: `${faker.company.catchPhraseAdjective()}-${faker.company.bsBuzz()}`,
8+
from: faker.date.future(),
9+
until: faker.date.future(),
10+
price: faker.finance.amount()
11+
}
12+
}
13+
14+
function byId(id) {
15+
const conference = generate()
16+
conference.id = id
17+
18+
return conference
19+
}
20+
21+
function latest(amount) {
22+
return [...Array(amount)].map(generate)
23+
}
24+
25+
exports.latest = latest
26+
exports.byId = byId
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const { isProduction } = require('envs')
2+
const fixture = require('models/conference/fixtures')
3+
4+
function latest(amount) {
5+
if (isProduction()) {
6+
throw new Error('No production database yet.')
7+
} else {
8+
return fixture.latest(amount)
9+
}
10+
}
11+
12+
function byId(id) {
13+
if (isProduction()) {
14+
throw new Error('No production database yet.')
15+
} else {
16+
return fixture.byId(id)
17+
}
18+
}
19+
20+
exports.latest = latest
21+
exports.byId = byId
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const test = require('ava')
2+
const model = require('models/conference')
3+
4+
test('latest', t => {
5+
const amount = 2
6+
const conferences = model.latest(amount)
7+
8+
t.is(conferences.length, amount)
9+
10+
conferences.forEach(conference => {
11+
t.truthy(conference.id)
12+
t.truthy(conference.name)
13+
t.truthy(conference.from)
14+
t.truthy(conference.until)
15+
t.truthy(conference.price)
16+
})
17+
})
18+
19+
test('byId', t => {
20+
const id = 'abc-edf'
21+
const conference = model.byId(id)
22+
23+
t.truthy(conference)
24+
t.is(conference.id, id)
25+
})

conferences/package.json

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "colloq-conferences",
3+
"version": "1.0.0",
4+
"description": "Confernces service",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "pm2 start processes.json",
8+
"stop": "pm2 stop processes.json",
9+
"dev:watch": "NODE_ENV=dev NODE_PATH=. DEBUG=* nodemon server.js",
10+
"dev:inspect": "NODE_ENV=dev NODE_PATH=. DEBUG=* node --inspect server.js",
11+
"test": "NODE_ENV=test NODE_PATH=. ava",
12+
"docker:build": "docker build -t $(whoami)/conferences .",
13+
"docker:start": "docker run -p 4000:4000 -d --name conferences $(whoami)/conferences",
14+
"docker:stop": "docker stop conferences",
15+
"docker:rm": "docker rm $(docker ps -a -q)"
16+
},
17+
"author": "Tobias Deekens <[email protected]> (http://tdeekens.name/)",
18+
"license": "MIT",
19+
"engines": {
20+
"node": ">=7",
21+
"npm": ">3"
22+
},
23+
"dependencies": {
24+
"debug": "2.2.0",
25+
"hapi": "15.2.0",
26+
"metrics-os": "1.0.1",
27+
"node-env-file": "0.1.8",
28+
"node-fetch": "1.6.3",
29+
"node-uuid": "1.4.7",
30+
"pm2": "2.0.19"
31+
},
32+
"devDependencies": {
33+
"ava": "^0.18.1",
34+
"faker": "3.1.0",
35+
"nodemon": "1.11.0",
36+
"supertest": "^3.0.0"
37+
}
38+
}

conferences/processes.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"apps": [{
3+
"name": "conferences",
4+
"script": "node",
5+
"args": "server.js",
6+
"merge_logs": true,
7+
"max_restarts": 20,
8+
"instances": 4,
9+
"max_memory_restart": "200M",
10+
"env": {
11+
"NODE_ENV": "prod",
12+
"NODE_PATH": "."
13+
}
14+
}]
15+
}

conferences/routes/conferences/get.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const debug = require('debug')('http-conferences')
2+
const model = require('models/conference')
3+
4+
exports.default = (req, reply) => {
5+
const { id } = req.params
6+
let conferences
7+
8+
debug('Start fetching conferences')
9+
10+
if (id) {
11+
conferences = model.byId(id)
12+
} else {
13+
conferences = model.latest(20)
14+
}
15+
16+
debug('...finished fetching conferences')
17+
18+
reply(conferences || {})
19+
}
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const test = require('ava')
2+
const { default: server } = require('server')
3+
4+
test('GET / statusCode', async t => {
5+
await server.inject({
6+
url: '/',
7+
method: 'GET'
8+
}).then(({ statusCode }) => {
9+
t.is(statusCode, 200)
10+
})
11+
})
12+
13+
test('GET / headers', async t => {
14+
await server.inject({
15+
url: '/',
16+
method: 'GET'
17+
}).then(({ headers }) => {
18+
t.is(headers['content-type'], 'application/json; charset=utf-8')
19+
})
20+
})
21+
22+
test('GET / properties', async t => {
23+
await server.inject({
24+
url: '/',
25+
method: 'GET'
26+
}).then(({ result: conferences }) => {
27+
conferences.forEach(conference => {
28+
t.truthy(conference.id)
29+
t.truthy(conference.name)
30+
t.truthy(conference.from)
31+
t.truthy(conference.until)
32+
t.truthy(conference.price)
33+
})
34+
})
35+
})
36+
37+
test('GET /:id', async t => {
38+
await server.inject({
39+
url: '/abc-def',
40+
method: 'GET'
41+
}).then(({ result: conference }) => {
42+
t.truthy(conference.id)
43+
t.truthy(conference.name)
44+
t.truthy(conference.from)
45+
t.truthy(conference.until)
46+
t.truthy(conference.price)
47+
})
48+
})
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const { default: getConferences } = require('routes/conferences/get')
2+
3+
function attachRoute(server) {
4+
server.route({
5+
method: 'GET',
6+
path: '/{id?}',
7+
handler: getConferences
8+
})
9+
}
10+
11+
exports.default = attachRoute

conferences/routes/health/get.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
exports.default = (req, reply) => {
2+
reply({ status: 'ok' })
3+
}

0 commit comments

Comments
 (0)