Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/logs/
/node_modules/
/logs/
/node_modules/
/test/
7 changes: 7 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"ExpandedNodes": [
""
],
"SelectedNode": "\\.gitignore",
"PreviewInSolutionExplorer": false
}
Binary file added .vs/slnx.sqlite
Binary file not shown.
Binary file added .vs/web-node/v16/.suo
Binary file not shown.
42 changes: 21 additions & 21 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
MIT License

Copyright (c) 2020 happybit

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
MIT License
Copyright (c) 2020 happybit
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# web-node
node web by koa2

项目使用koa2框架开发mvc模式的web引用

使用pm2管理多进程

登录session信息使用redis服务器单独存储

普通数据使用mysql,sequelize进行对象关系映射

包含websocket引用、测试程序

提供rest接口

引入mongoose,尚未定义对应表规则

使用长连接:redis、mysql、mongodb

查看MySQL通信连接信息
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
# web-node
node web by koa2
项目使用koa2框架开发mvc模式的web引用
使用pm2管理多进程
登录session信息使用redis服务器单独存储
普通数据使用mysql,sequelize进行对象关系映射
包含websocket引用、测试程序
提供rest接口
引入mongoose,尚未定义对应表规则
使用长连接:redis、mysql、mongodb
查看MySQL通信连接信息
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
74 changes: 37 additions & 37 deletions assets/js/websocket.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
var host = location.host;//本地域名
var port = 32772;//与docker 容器中web端口对应的本地端口
var wsServer = 'ws://'+host+':'+port+'/wechat';
var websocket = createWebSocket();

function createWebSocket(){
var websocket = new WebSocket(wsServer);
websocket.onopen = function (evt) { onOpen(evt) };
websocket.onclose = function (evt) { onClose(evt) };
websocket.onmessage = function (evt) { onMessage(evt) };
websocket.onerror = function (evt) { onError(evt) };
return websocket;
}
function onOpen(evt) {
websocket.send('_SYN_'+new Date().getTime());
console.log("Connected to ",websocket.url);
websocket.HeartBeat = setInterval(() => {
websocket.send('_SYN_'+new Date().getTime());
}, 40000);
}
function onClose(evt) {
console.log("Disconnected");
clearInterval(websocket.HeartBeat);
websocket.HeartBeat = undefined;
}
function onError(evt) {
console.log('Error occured: ' , evt);
clearInterval(websocket.HeartBeat);
websocket.HeartBeat = undefined;
setTimeout(() => {
websocket = createWebSocket();//重新连接
}, 6000);
}

function onMessage(evt) {
console.log('Retrieved data from server: ' , evt.data);
}
var host = location.host;//本地域名
var port = 32772;//与docker 容器中web端口对应的本地端口
var wsServer = 'ws://'+host+':'+port+'/wechat';
var websocket = createWebSocket();
function createWebSocket(){
var websocket = new WebSocket(wsServer);
websocket.onopen = function (evt) { onOpen(evt) };
websocket.onclose = function (evt) { onClose(evt) };
websocket.onmessage = function (evt) { onMessage(evt) };
websocket.onerror = function (evt) { onError(evt) };
return websocket;
}
function onOpen(evt) {
websocket.send('_SYN_'+new Date().getTime());
console.log("Connected to ",websocket.url);
websocket.HeartBeat = setInterval(() => {
websocket.send('_SYN_'+new Date().getTime());
}, 40000);
}
function onClose(evt) {
console.log("Disconnected");
clearInterval(websocket.HeartBeat);
websocket.HeartBeat = undefined;
}
function onError(evt) {
console.log('Error occured: ' , evt);
clearInterval(websocket.HeartBeat);
websocket.HeartBeat = undefined;
setTimeout(() => {
websocket = createWebSocket();//重新连接
}, 6000);
}
function onMessage(evt) {
console.log('Retrieved data from server: ' , evt.data);
}
12 changes: 6 additions & 6 deletions biz/UserBiz.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class UserBiz{
static a(){

}
}

class UserBiz{
static a(){
}
}
module.exports = UserBiz;
12 changes: 6 additions & 6 deletions config/params.mongodb.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
host: '127.0.0.1',
port:27017,
username:'root',
password:'mnbvcxz_123',
db:'node'
module.exports = {
host: '127.0.0.1',
port:27017,
username:'root',
password:'mnbvcxz_123',
db:'node'
}
12 changes: 6 additions & 6 deletions config/params.mysql.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
host:'172.17.0.3',
port:'3306',
username:'root',
password:'mnbvcxz@123',
database:'test'
module.exports = {
host:'172.17.0.2',
port:'3306',
username:'root',
password:'mnbvcxz@123',
database:'test'
}
8 changes: 4 additions & 4 deletions config/params.redis.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
host:'172.17.0.4',
port: 6379,
auth_pass:'mnbvcxz_123'
module.exports = {
host:'172.17.0.4',
port: 6379,
auth_pass:'mnbvcxz_123'
}
28 changes: 14 additions & 14 deletions controller/api.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@

module.exports = {
"GET /api/test":async (ctx, next) => {
ctx.rest({name:'wlz','test':true,'api':'test'});
},
"GET /api/test1":async (ctx, next) => {
ctx.rest({name:'wlz','test':true,'api':'test1'});
},
"GET /api/test2":async (ctx, next) => {
ctx.rest({name:'wlz','test':true,'api':'test2'});
},
"GET /api/testerr":async (ctx, next) => {
ctx.restError('test:testerr','测试错误接口1');
}
module.exports = {
"GET /api/test":async (ctx, next) => {
ctx.rest({name:'wlz','test':true,'api':'test'});
},
"GET /api/test1":async (ctx, next) => {
ctx.rest({name:'wlz','test':true,'api':'test1'});
},
"GET /api/test2":async (ctx, next) => {
ctx.rest({name:'wlz','test':true,'api':'test2'});
},
"GET /api/testerr":async (ctx, next) => {
ctx.restError('test:testerr','测试错误接口1');
}
}
18 changes: 9 additions & 9 deletions controller/cookie.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@


module.exports = {
"GET /testcookie":async (ctx, next) => {
ctx.set('Set-Cookie', 'foo=bar; Path=/; HttpOnly;maxAge:0');
ctx.cookies.set('name', 'tobi', { signed: true });
ctx.response.body = 'ok';
await next();
}
module.exports = {
"GET /testcookie":async (ctx, next) => {
ctx.set('Set-Cookie', 'foo=bar; Path=/; HttpOnly;maxAge:0');
ctx.cookies.set('name', 'tobi', { signed: true });
ctx.response.body = 'ok';
await next();
}
}
48 changes: 24 additions & 24 deletions controller/index.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
const {Op} = require('sequelize');
const path = require('path');

module.exports = {
"GET /":async ( ctx, next )=>{
try{
ctx.state.where = {
'is':'adc'
}
await ctx.render('index.html',{test:{time:new Date().getTime()}});
}catch(e){
ctx.response.body = e.message;
}
await next();
},
"GET /wechat":async ( ctx, next )=>{
try{
await ctx.render('wechat.html',{});
}catch(e){
ctx.response.body = e.message;
}
await next();
}

const {Op} = require('sequelize');
const path = require('path');
module.exports = {
"GET /":async ( ctx, next )=>{
try{
ctx.state.where = {
'is':'adc'
}
await ctx.render('index.html',{test:{time:new Date().getTime()}});
}catch(e){
ctx.response.body = e.message;
}
await next();
},
"GET /wechat":async ( ctx, next )=>{
try{
await ctx.render('wechat.html',{});
}catch(e){
ctx.response.body = e.message;
}
await next();
}
}
22 changes: 11 additions & 11 deletions controller/needle.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const Needle = require('needle');
module.exports = {
"GET /sinaimg":async ( ctx, next )=>{
await Needle('get','https://wx4.sinaimg.cn/large/60718250ly1gflpmgpk77j20bv0bvjrp.jpg').then((res)=>{
ctx.response.type = 'image/jpg';
ctx.response.body = res.body;
}).catch((err)=>{
ctx.response.type = 'ico';
ctx.response.body = fs.createReadStream('./favicon.ico');
})
}
const Needle = require('needle');
module.exports = {
"GET /sinaimg":async ( ctx, next )=>{
await Needle('get','https://wx4.sinaimg.cn/large/60718250ly1gflpmgpk77j20bv0bvjrp.jpg').then((res)=>{
ctx.response.type = 'image/jpg';
ctx.response.body = res.body;
}).catch((err)=>{
ctx.response.type = 'ico';
ctx.response.body = fs.createReadStream('./favicon.ico');
})
}
}
Loading