Skip to content

Commit 8a87a18

Browse files
committed
add kubernetes ingress and healthcheck
1 parent 7cdc770 commit 8a87a18

File tree

5 files changed

+154
-116
lines changed

5 files changed

+154
-116
lines changed

README.md

Lines changed: 90 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,90 @@
1-
# Koa Vue Fullstack Boilerplate
2-
##### 🎉🎉🎉 Upgrade Webpack to v4!
3-
<sup> Project based on Webpack3 is in [Releases](https://github.com/yunhan0/koa-vue-fullstack/releases). </sup>
4-
5-
### Preface
6-
##### Vue.js, Koa.js, Node.js, and MongoDB fullstack lightweight example application. Authentication, CRUD, and access control included.
7-
This project aims to build a small but structured full-stack application, so it would be relatively clear for a programmer/beginner to understand how to build a website from scratch.
8-
9-
### Demo:
10-
Click [here](http://yunhan.li/koa-vue-fullstack) to see demo website. Server is deployed on heroku's free plan :) 🐢🐢🐢.<br>
11-
<pre>
12-
13-
password: 123456
14-
</pre>
15-
16-
### Environment:
17-
- Server
18-
- [Koa](http://koajs.com/)
19-
- Koa Router, Koa Cors, Koa Bodyparser
20-
- Mongoose
21-
- Node ~~v8.9.4~~ v10.12.0
22-
- Client
23-
- [Vue](https://vuejs.org/)
24-
- [iView](https://www.iviewui.com/)
25-
- [Axios](https://github.com/axios/axios) (HTTP Client Library)
26-
- ~~Webpack 3~~ Webpack 4
27-
- WebpackDevServer (Development mode only)
28-
29-
### Architecture
30-
31-
├─client # frontend folder
32-
│ ├─src # frontend src
33-
│ │ ├─api
34-
│ │ ├─router
35-
│ │ ├─styles
36-
│ │ ├─components
37-
│ │ ├─store # state management
38-
│ │ │ └─modules
39-
│ │ └─view # app pages
40-
│ │ └─auth
41-
│ └─static # static folder
42-
|
43-
└─server # server folder
44-
└─src # server src
45-
├─api # server api list
46-
│ ├─auth # completely token-based authentication
47-
│ ├─thing
48-
│ └─user
49-
├─config # server configurations
50-
│ ├─index # default server port, mongo uri, etc settings
51-
│ ├─security # security settins
52-
│ └─seed # populate database with sample data on server start
53-
├─entry.js # entry file for environment setup
54-
├─main.js # main file after entry
55-
└─routes.js # router
56-
57-
### Run through Docker
58-
```bash
59-
cd server # You can boost the server by using Docker
60-
docker-compose up
61-
# Open a new tab
62-
cd client
63-
npm install
64-
npm start
65-
```
66-
67-
### Setup Locally:
68-
- Steps:
69-
The server and client are completely seperated in this project, so go to each client and server folder and run:
70-
71-
```bash
72-
cd client
73-
npm install
74-
npm start # Running dev client
75-
# Open a new tab
76-
mongod # Boost Mongo DB
77-
# Open a new tab
78-
cd server
79-
# CREATE a .env file under server folder, and copy and paste the contents of .env.default file into this .env, and assign values
80-
touch .env
81-
npm install
82-
npm start # Running dev server
83-
```
84-
85-
- Others:
86-
```bash
87-
npm run build # Running production mode
88-
npm run eslint # Check your coding style
89-
npm run eslint-fix # Use auto ESLint fix
90-
```
1+
# Koa Vue Fullstack Boilerplate
2+
##### 🎉🎉🎉 Upgrade Webpack to v4!
3+
<sup> Project based on Webpack3 is in [Releases](https://github.com/yunhan0/koa-vue-fullstack/releases). </sup>
4+
5+
### Preface
6+
##### Vue.js, Koa.js, Node.js, and MongoDB fullstack lightweight example application. Authentication, CRUD, and access control included.
7+
This project aims to build a small but structured full-stack application, so it would be relatively clear for a programmer/beginner to understand how to build a website from scratch.
8+
9+
### Demo:
10+
Click [here](http://yunhan.li/koa-vue-fullstack) to see demo website.<br>
11+
<pre>
12+
13+
password: 123456
14+
</pre>
15+
16+
### Environment:
17+
- Server
18+
- [Koa](http://koajs.com/)
19+
- Koa Router, Koa Cors, Koa Bodyparser
20+
- Mongoose
21+
- Node ~~v8.9.4~~ v10.12.0
22+
- Client
23+
- [Vue](https://vuejs.org/)
24+
- [iView](https://www.iviewui.com/)
25+
- [Axios](https://github.com/axios/axios) (HTTP Client Library)
26+
- ~~Webpack 3~~ Webpack 4
27+
- WebpackDevServer (Development mode only)
28+
29+
### Architecture
30+
31+
├─client # frontend folder
32+
│ ├─src # frontend src
33+
│ │ ├─api
34+
│ │ ├─router
35+
│ │ ├─styles
36+
│ │ ├─components
37+
│ │ ├─store # state management
38+
│ │ │ └─modules
39+
│ │ └─view # app pages
40+
│ │ └─auth
41+
│ └─static # static folder
42+
|
43+
└─server # server folder
44+
└─src # server src
45+
├─api # server api list
46+
│ ├─auth # completely token-based authentication
47+
│ ├─thing
48+
│ └─user
49+
├─config # server configurations
50+
│ ├─index # default server port, mongo uri, etc settings
51+
│ ├─security # security settins
52+
│ └─seed # populate database with sample data on server start
53+
├─entry.js # entry file for environment setup
54+
├─main.js # main file after entry
55+
└─routes.js # router
56+
57+
### Run through Docker
58+
```bash
59+
cd server # You can boost the server by using Docker
60+
docker-compose up
61+
# Open a new tab
62+
cd client
63+
npm install
64+
npm start
65+
```
66+
67+
### Setup Locally:
68+
- Steps:
69+
The server and client are completely seperated in this project, so go to each client and server folder and run:
70+
71+
```bash
72+
cd client
73+
npm install
74+
npm start # Running dev client
75+
# Open a new tab
76+
mongod # Boost Mongo DB
77+
# Open a new tab
78+
cd server
79+
# CREATE a .env file under server folder, and copy and paste the contents of .env.default file into this .env, and assign values
80+
touch .env
81+
npm install
82+
npm start # Running dev server
83+
```
84+
85+
- Others:
86+
```bash
87+
npm run build # Running production mode
88+
npm run eslint # Check your coding style
89+
npm run eslint-fix # Use auto ESLint fix
90+
```

kubernetes/ingress.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: networking.k8s.io/v1beta1
2+
kind: Ingress
3+
metadata:
4+
name: koa-vue-fullstack-ingress
5+
annotations:
6+
kubernetes.io/ingress.class: nginx
7+
cert-manager.io/cluster-issuer: letsencrypt-prod
8+
spec:
9+
tls:
10+
- hosts:
11+
- k8s.yunhan.li
12+
secretName: koa-vue-fullstack-stack-secrets
13+
rules:
14+
- host: k8s.yunhan.li
15+
http:
16+
paths:
17+
- path: /
18+
backend:
19+
serviceName: koa-vue-fullstack-server
20+
servicePort: 3001

kubernetes/secrets.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: koa-vue-fullstack-stack-secrets
5+
type: Opaque

kubernetes/server.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ spec:
1818
image: yunhan0/koa-vue-fullstack:server
1919
ports:
2020
- containerPort: 3000
21+
env:
22+
- name: DB_URI
23+
value: mongodb://mongodb-service.yunhan.svc.cluster.local:27017/snapshot
24+
livenessProbe:
25+
httpGet:
26+
path: /health-check
27+
port: 3000
28+
initialDelaySeconds: 3
29+
periodSeconds: 3
2130

2231
---
2332
apiVersion: v1

server/src/routes.js

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
1-
module.exports = function(app) {
2-
// Customized error handling, default error code: 500
3-
app.use(async (ctx, next) => {
4-
try {
5-
await next()
6-
} catch (err) {
7-
// Handle Validation Error
8-
if(err.name === 'ValidationError') {
9-
err.status = 422
10-
}
11-
// Handle Mongoose Item Duplication Error
12-
if (err.name === 'BulkWriteError' && err.code === 11000) {
13-
err.status = 422
14-
}
15-
ctx.status = err.status || 500
16-
ctx.body = { message: err.message }
17-
}
18-
})
19-
app.use(require('./api/auth').routes())
20-
app.use(require('./api/user').routes())
21-
// route middleware to verify a token
22-
app.use(require('./api/auth/service').isAuthenticated)
23-
app
24-
.use(require('./api/thing').routes())
25-
.use(require('./api/thing').allowedMethods())
26-
}
1+
module.exports = function(app) {
2+
// Customized error handling, default error code: 500
3+
app.use(async (ctx, next) => {
4+
try {
5+
await next()
6+
} catch (err) {
7+
// Handle Validation Error
8+
if(err.name === 'ValidationError') {
9+
err.status = 422
10+
}
11+
// Handle Mongoose Item Duplication Error
12+
if (err.name === 'BulkWriteError' && err.code === 11000) {
13+
err.status = 422
14+
}
15+
ctx.status = err.status || 500
16+
ctx.body = { message: err.message }
17+
}
18+
})
19+
20+
// Health check does not require authentication
21+
app.use(require('./api/health-check').routes())
22+
23+
app.use(require('./api/auth').routes())
24+
app.use(require('./api/user').routes())
25+
// route middleware to verify a token
26+
app.use(require('./api/auth/service').isAuthenticated)
27+
app
28+
.use(require('./api/thing').routes())
29+
.use(require('./api/thing').allowedMethods())
30+
}

0 commit comments

Comments
 (0)