adding docker-compose
This commit is contained in:
parent
4ecbb5b68c
commit
e2fff7fa58
8
.gitignore
vendored
8
.gitignore
vendored
@ -1,3 +1,7 @@
|
|||||||
.idea/
|
.idea/
|
||||||
./node_modules/
|
./redis_conf/
|
||||||
./package-lock.json
|
./redis_data/
|
||||||
|
./node_logs/
|
||||||
|
./node_app./
|
||||||
|
node_modules/
|
||||||
|
./node_app/package-lock.json
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
This is a simple application to setup your own smarthome with some ESP8266.
|
This is a simple application to setup your own smarthome with some ESP8266.
|
||||||
The server is based on Nodejs and can be run on a Raspberry Pi.
|
The server is based on Nodejs and can be run on a Raspberry Pi.
|
||||||
You can change the public ports `8080` (web UI) and `8081` (websocket).
|
You can change the public ports `8080` (web UI) and `8081` (websocket) in `docker-compose.yml`.
|
||||||
To run the server simply execute `server.js`.
|
To run the server simply execute `docker-compose`.
|
||||||
```
|
```
|
||||||
screen -A -m -d -S short_url nodejs server.js
|
docker-compose -p surl up -d
|
||||||
```
|
```
|
||||||
It's recommended to use a reverse proxy like nginx.
|
It's recommended to use a reverse proxy like nginx.
|
||||||
|
|
||||||
|
31
docker-compose.yml
Normal file
31
docker-compose.yml
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
version: '3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
node:
|
||||||
|
image: node
|
||||||
|
container_name: esp-smarthome_node
|
||||||
|
restart: always
|
||||||
|
ports:
|
||||||
|
- "8080:8080"
|
||||||
|
- "8081:8081"
|
||||||
|
volumes:
|
||||||
|
- ./node_app/:/home/node/app/
|
||||||
|
# - ./node_modules/:/home/node/app/node_modules/
|
||||||
|
- ./node_logs/:/var/log/
|
||||||
|
working_dir: /home/node/app/
|
||||||
|
environment:
|
||||||
|
- NODE_ENV=production
|
||||||
|
command: sh -c 'npm i && nodejs server.js'
|
||||||
|
links:
|
||||||
|
- redis
|
||||||
|
redis:
|
||||||
|
image: redis
|
||||||
|
container_name: esp-smarthome_redis
|
||||||
|
expose:
|
||||||
|
- 6379
|
||||||
|
restart: always
|
||||||
|
volumes:
|
||||||
|
- ./redis_data/:/var/lib/redis/
|
||||||
|
- ./redis_conf/:/usr/local/etc/redis/
|
||||||
|
environment:
|
||||||
|
- REDIS_REPLICATION_MODE=master
|
10
node_app/package.json
Normal file
10
node_app/package.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"name": "esp-smarthome_server",
|
||||||
|
"version": "1.1.0",
|
||||||
|
"dependencies": {
|
||||||
|
"mime": "^2.4.6",
|
||||||
|
"redis": "^3.0.2",
|
||||||
|
"ws": "^7.3.1",
|
||||||
|
"xmlhttprequest": "^1.8.0"
|
||||||
|
}
|
||||||
|
}
|
@ -12,7 +12,7 @@
|
|||||||
<link rel="stylesheet" type="text/css" href="/sym/dark.css"/>
|
<link rel="stylesheet" type="text/css" href="/sym/dark.css"/>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const wsurl = 'ws://192.168.1.101:8081'
|
const wsurl = 'ws://127.0.0.1:8081'
|
||||||
const socket = new WebSocket(wsurl)
|
const socket = new WebSocket(wsurl)
|
||||||
|
|
||||||
socket.onopen = () => {
|
socket.onopen = () => {
|
||||||
@ -67,7 +67,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div id="error-box" class="error">
|
<div id="error-box" class="error">
|
||||||
<div onclick="this.parentNode.style.display = 'none'" style="position: absolute; top:5px; right: 5px;" class="sym_btn-invisible">
|
<div onclick="this.parentNode.style.display = 'none'" style="position: absolute; top:5px; right: 5px;" class="sym_btn-invisible">
|
||||||
<img class="icon" src="./sym/ic_close_white_24px.svg">
|
<img class="icon" src="sym/ic_close_white_24px.svg">
|
||||||
</div>
|
</div>
|
||||||
<div id="error-message" class="btn-text">
|
<div id="error-message" class="btn-text">
|
||||||
</div>
|
</div>
|
Before Width: | Height: | Size: 265 B After Width: | Height: | Size: 265 B |
@ -13,7 +13,7 @@ let led1_status = 'off';
|
|||||||
|
|
||||||
//redis client
|
//redis client
|
||||||
const redis_cli = redis.createClient({
|
const redis_cli = redis.createClient({
|
||||||
host: '127.0.0.1',
|
host: 'redis',
|
||||||
port: 6379
|
port: 6379
|
||||||
})
|
})
|
||||||
redis_cli.on("error", function (error) {
|
redis_cli.on("error", function (error) {
|
||||||
@ -99,7 +99,6 @@ let checkstat = setInterval(to => {
|
|||||||
xhr.ontimeout = function(e) {ws.send('error;device "led1" is offline')}
|
xhr.ontimeout = function(e) {ws.send('error;device "led1" is offline')}
|
||||||
xhr.send();
|
xhr.send();
|
||||||
setTimeout(to => {if (xhr.readyState !== 4){
|
setTimeout(to => {if (xhr.readyState !== 4){
|
||||||
wss.clients.forEach(clients => clients.send(`${key};offline`))
|
|
||||||
device_available = "offline"
|
device_available = "offline"
|
||||||
xhr.abort()
|
xhr.abort()
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user