Skip to content

Commit

Permalink
Merge pull request #22 from jhotmann/automated-tests
Browse files Browse the repository at this point in the history
Big Refactor, Many Automated Tests
  • Loading branch information
jhotmann authored Oct 16, 2021
2 parents 4294ae5 + 2ff5b4d commit f4e6516
Show file tree
Hide file tree
Showing 56 changed files with 9,876 additions and 2,353 deletions.
Binary file removed .DS_Store
Binary file not shown.
6 changes: 4 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"commonjs": true,
"es2021": true,
"node": true,
"jquery": true
"jquery": true,
"jest/globals": true,
},
"extends": [
"airbnb-base"
Expand All @@ -19,5 +20,6 @@
"no-param-reassign": "warn",
"max-len": "off",
"no-console": "off"
}
},
"plugins": ["jest"]
}
15 changes: 14 additions & 1 deletion .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,29 @@ on:
push:
branches:
- 'main'
- 'automated-tests'
tags:
- 'v*'

jobs:

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Test using Node.js
uses: actions/setup-node@v1
with:
node-version: '16'
- run: npm ci
- run: npm test

build:
needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
# Generate container tags
- name: Docker meta
id: meta
uses: docker/metadata-action@v3
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ typings/
# next.js build output
.next

data/
data/
.DS_Store
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
FROM node:16

ENV BEHIND_PROXY=true
ENV NODE_ENV=production

WORKDIR /app
COPY package*.json ./
RUN npm ci
RUN npm i -g forever
ENV BEHIND_PROXY=true

COPY . .

Expand Down
21 changes: 17 additions & 4 deletions bin/www
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
* Module dependencies.
*/

const aedes = require('aedes')();
const http = require('http');
const app = require('../app');
const db = require('../src/database');

(async () => { await db.dataMigration(); })();
const ws = require('websocket-stream');
const app = require('../src/app');
const mqtt = require('../src/mqtt');

/**
* Get port from environment and store in Express.
Expand All @@ -22,6 +22,8 @@ app.set('port', port);
*/

const server = http.createServer(app);
const mqttServer = http.createServer();
ws.createServer({ server: mqttServer }, aedes.handle);

/**
* Listen on provided port, on all network interfaces.
Expand All @@ -31,6 +33,10 @@ server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

mqttServer.listen(process.env.MQTT_PORT || 8888, () => {
console.log(`MQTT websocket server listening on port ${process.env.MQTT_PORT || 8888}`);
});

/**
* Normalize a port into a number, string, or false.
*/
Expand Down Expand Up @@ -86,3 +92,10 @@ function onListening() {
const bind = typeof addr === 'string' ? `pipe ${addr}` : `port ${addr.port}`;
console.log(`Express server listening on ${bind}`);
}

// MQTT Event Handlers

mqtt.set(aedes);
aedes.authenticate = mqtt.authenticate;
aedes.authorizeSubscribe = mqtt.authorizeSubscribe;
aedes.authorizePublish = mqtt.authorizePublish;
Loading

0 comments on commit f4e6516

Please sign in to comment.