Skip to content

Commit

Permalink
use redis
Browse files Browse the repository at this point in the history
  • Loading branch information
ffaerber committed Dec 3, 2018
1 parent d852dd5 commit b8fb71f
Show file tree
Hide file tree
Showing 14 changed files with 187 additions and 3,321 deletions.
13 changes: 7 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
ARG QEMU
ARG NPM_OPTIONS
ARG BASE_IMAGE=amd64/debian:stretch-slim
ARG BASE_IMAGE=amd64/debian:9.5-slim
FROM ${BASE_IMAGE}

ADD ${QEMU} /usr/bin/${QEMU}

RUN apt-get update && \
apt-get install -y \
vim \
gnupg \
curl
apt-get install -y \
vim \
gnupg \
iputils-ping \
curl

RUN curl -sL https://deb.nodesource.com/setup_9.x | sh
RUN curl -sL https://deb.nodesource.com/setup_11.x | sh
RUN apt-get install -y nodejs

RUN mkdir -p /usr/src/app
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
[ ![appsample](https://travis-ci.org/ffaerber/appsample.svg?branch=master)](https://travis-ci.org/ffaerber/appsample)

# appsample
this is a koa.js application for testing modern node based microservices.

this is a example api application for testing and learning.

- docker arm https://www.youtube.com/watch?v=nrBYUw1Pz5I
- docker CI https://blog.hypriot.com/post/setup-simple-ci-pipeline-for-arm-images/
- testing https://www.valentinog.com/blog/testing-api-koa-jest/
- test api |
- create `curl -X POST -H 'Content-Type: application/json' -d '{"id":"123","title":"test","body":"my Article"}' http://localhost:3000/api/v1/articles`
- update `curl -X PUT -H 'Content-Type: application/json' -d '{"id":"123","title":"test","body":"my New Article"}' http://localhost:3000/api/v1/articles/123`
- show `curl http://localhost:3000/api/v1/articles/123`
- delete `curl -X "DELETE" http://localhost:3000/api/v1/articles/123`
19 changes: 8 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
version: '3.3'
version: "3.3"

volumes:
node_modules:
driver: local


services:

# dev-app:
# image: ffaerber/appsample
# # build:
# # context: .
# # image: ffaerber/appsample
# build:
# context: .
# ports:
# - "3000:3000"
# environment:
# - REDIS_HOST=redis://redis-db
# REDIS_HOST: redis://redis-db
# volumes:
# - node_modules:/usr/src/app/node_modules


test-app:
build:
context: .
command: npm test
environment:
MONGO_HOST: mongodb://mongo-db/test
REDIS_HOST: redis://redis-db
volumes:
- node_modules:/usr/src/app/node_modules
- ./:/usr/src/app

mongo-db:
image: mongo
redis-db:
image: redis
5 changes: 0 additions & 5 deletions libs/mongoose.js

This file was deleted.

3 changes: 3 additions & 0 deletions libs/redis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const Redis = require('ioredis')

module.exports = new Redis(process.env.REDIS_HOST)
7 changes: 7 additions & 0 deletions middlewares/redis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const redis = require('../libs/redis')

module.exports = () => async (ctx, next) => {
ctx.redis = redis
console.log('Redis created')
await next()
}
Loading

0 comments on commit b8fb71f

Please sign in to comment.