ソースアップ

This commit is contained in:
ry-yamafuji 2024-06-12 06:58:45 +09:00
parent 21cd55ccde
commit 5e28005d75
2 changed files with 45 additions and 0 deletions

20
Dockerfile Normal file
View File

@ -0,0 +1,20 @@
# Use the official Node.js image with Alpine
FROM node:alpine
# Create and change to the app directory
WORKDIR /usr/src/app
# Copy package.json and package-lock.json files to the working directory
COPY package*.json ./
# Install the dependencies
RUN npm install
# Copy the application source
COPY . .
# Expose the MQTT port
EXPOSE 1883
# Run the MQTT broker
CMD ["node", "broker.js"]

View File

@ -0,0 +1,25 @@
npm install aedes --save
npm install aedes-cli --global
```
const aedes = require('aedes')();
const server = require('net').createServer(aedes.handle);
const port = 1883;
server.listen(port, function () {
console.log('Aedes broker started and listening on port ', port);
});
aedes.on('client', function (client) {
console.log('Client Connected:', client.id);
});
aedes.on('clientDisconnect', function (client) {
console.log('Client Disconnected:', client.id);
});
aedes.on('publish', function (packet, client) {
console.log('Published:', packet.payload.toString());
});
```