Skip to content

Commit f33c54f

Browse files
author
Allen Wang
committed
update folder structure
1 parent 27efed5 commit f33c54f

10 files changed

+38
-40
lines changed

Diff for: app/app.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ var app = express();
1212

1313
var serverName = process.env.SERVER_NAME || 'SERVER';
1414
var store = new RedisStore({
15-
// host: 'redis-master',
15+
// host: 'localhost',
1616
// port: 6379,
1717
// client: new Redis(6379, 'redis-master'),
1818
client: new Redis({
19-
sentinels: [{ host: 'redis-sentinel-1', port: 26379 }],
19+
sentinels: [{ host: 'redis-sentinel', port: 26379 }],
2020
name: 'mymaster'
2121
}),
22+
// client: new Redis(),
2223
ttl: 260
2324
});
2425
// view engine setup
@@ -61,7 +62,18 @@ app.get('/main', function(req, res, next) {
6162
if (!req.session.login) return res.redirect('/login');
6263
next();
6364
}, function(req, res, next) {
64-
res.render('index', { title: serverName });
65+
store.all(function(err, sessions) {
66+
var users = sessions.filter(function(session) {
67+
return session.login;
68+
}).map(function(session) {
69+
return session.user;
70+
});
71+
res.render('index', {
72+
title: serverName,
73+
user: req.session.user,
74+
users: users
75+
});
76+
})
6577
});
6678

6779
app.get('/login', function(req, res, next) {
@@ -70,6 +82,7 @@ app.get('/login', function(req, res, next) {
7082

7183
app.post('/login', function(req, res, next) {
7284
req.session.login = true;
85+
req.session.user = req.body.username
7386
res.redirect('/main');
7487
});
7588

Diff for: app/views/index.jade

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ extends layout
22

33
block content
44
h1= title
5-
p Welcome to #{title}
6-
5+
p Hello #{user}, welcome to #{title}
6+
hr
7+
p Online User List:
8+
ul
9+
for name in users
10+
li= name
11+
hr
712
form(action="/logout", method="get")
813
input(type="submit",value="logout")

Diff for: app/views/login.jade

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ extends layout
33
block content
44
h1 Please login first
55
form(action="/login", method="post")
6-
input(name="username", placeholder="username")
6+
input(name="username", placeholder="User Name")
77
br
8-
input(type="password",name="username", placeholder="password")
98
br
10-
input(type="submit",value="submit")
9+
input(type="submit",value="Login")
1110

1211

Diff for: docker-compose.yaml

+7-9
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ services:
44
container_name: server-1
55
build: ./app
66
depends_on:
7-
- redis-sentinel-1
7+
- redis-sentinel
88
environment:
99
- SERVER_NAME=server-1
1010

1111
server-2:
1212
container_name: server-2
1313
build: ./app
1414
depends_on:
15-
- redis-sentinel-1
15+
- redis-sentinel
1616
environment:
1717
- SERVER_NAME=server-2
1818

@@ -27,14 +27,12 @@ services:
2727
depends_on:
2828
- redis-master
2929

30-
redis-sentinel-1:
31-
container_name: redis-sentinel-1
32-
image: redis
30+
redis-sentinel:
31+
container_name: redis-sentinel
32+
build: ./redis
3333
depends_on:
3434
- redis-slave
35-
volumes:
36-
- ./redis-sentinel-1.conf:/etc/nginx/sentinel.conf
37-
command: redis-server /etc/nginx/sentinel.conf --sentinel --port 26379
35+
command: redis-server /etc/redis-sentinel.conf --sentinel --port 26379
3836

3937
nginx:
4038
container_name: load-balancer
@@ -43,6 +41,6 @@ services:
4341
- server-1
4442
- server-2
4543
volumes:
46-
- ./nginx.conf:/etc/nginx/nginx.conf:ro
44+
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
4745
ports:
4846
- 80:80

Diff for: nginx.conf renamed to nginx/nginx.conf

File renamed without changes.

Diff for: redis-sentinel-1.conf

-19
This file was deleted.

Diff for: redis/Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM redis
2+
COPY ./redis-sentinel.conf /etc
3+
RUN chmod -R 666 /etc/redis-sentinel.conf
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#daemonize yes
22
#port 26379
3-
sentinel myid 2ff8a11b3d6a13bc867062ca8597e0614d94dce8
4-
sentinel monitor mymaster 172.19.0.2 6379 1
5-
sentinel down-after-milliseconds mymaster 3000
3+
sentinel monitor mymaster redis-master 6379 1
4+
sentinel down-after-milliseconds mymaster 1000
65
sentinel parallel-syncs mymaster 2
76
#sentinel auth-pass mymaster 123456
87
#sentinel notification-script mymaster /etc/redis/notify.sh
98
#sentinel client-reconfig-script mymaster /etc/redis/failover.sh
10-
#logfile /var/log/redis/redis-sentinel.log
9+
#logfile /var/log/redis/redis-sentinel.log
File renamed without changes.

0 commit comments

Comments
 (0)