Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
egg-websocket
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
huanglu
egg-websocket
Commits
59d498c9
Commit
59d498c9
authored
May 21, 2021
by
huanglu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: kkk
parent
f7f1ec72
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
84 additions
and
57 deletions
+84
-57
.npmrc
.npmrc
+5
-0
auth.ts
app/controller/auth.ts
+18
-0
auth.ts
app/middleware/auth.ts
+32
-0
jwt.ts
app/middleware/jwt.ts
+0
-25
router.ts
app/router.ts
+2
-0
auth.ts
app/router/auth.ts
+8
-0
config.default.ts
config/config.default.ts
+7
-22
index.d.ts
typings/app/controller/index.d.ts
+3
-1
helper.d.ts
typings/app/extend/helper.d.ts
+1
-1
index.d.ts
typings/app/index.d.ts
+1
-1
index.d.ts
typings/app/middleware/index.d.ts
+3
-3
index.d.ts
typings/app/model/index.d.ts
+1
-1
index.d.ts
typings/app/service/index.d.ts
+1
-1
index.d.ts
typings/config/index.d.ts
+1
-1
plugin.d.ts
typings/config/plugin.d.ts
+1
-1
No files found.
.npmrc
0 → 100644
View file @
59d498c9
registry=http://git.jksxb.cn:8081/repository/geek/
disturl=https://npm.taobao.org/dist
sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
phantomjs_cdnurl=https://npm.taobao.org/mirrors/phantomjs/
fsevents_binary_host_mirror=http://npm.taobao.org/mirrors/fsevents/
app/controller/auth.ts
0 → 100644
View file @
59d498c9
import
{
Controller
}
from
'egg'
;
export
default
class
Auth
extends
Controller
{
async
login
()
{
const
{
ctx
}
=
this
console
.
log
(
'=== login: '
,
ctx
.
query
)
ctx
.
body
=
ctx
.
helper
.
success
({
userId
:
''
})
}
async
getUserInfo
()
{
this
.
ctx
.
body
=
{
ll
:
'sfsfs'
}
}
}
app/middleware/auth.ts
0 → 100644
View file @
59d498c9
import
{
Context
,
EggAppConfig
}
from
'egg'
;
export
default
function
jwt
(
options
:
EggAppConfig
[
'jwt'
])
{
return
async
(
ctx
:
Context
,
next
:()
=>
Promise
<
any
>
)
=>
{
//拿到不需要验证的token的路由
const
routerAuth
=
ctx
.
app
.
config
.
routerNotAuth
;
//获取当前路由
const
url
=
ctx
.
url
;
console
.
log
(
'=====: '
,
routerAuth
,
url
)
//判断当前路由是否需要验证token
const
flag
=
routerAuth
.
includes
(
url
)
if
(
flag
)
{
await
next
();
}
else
{
//获取token,如果没有传入token,则为空
const
token
=
ctx
.
request
.
headers
.
authorization
as
string
;
// 解析token
try
{
ctx
.
app
.
jwt
.
verify
(
token
,
options
.
secret
);
await
next
();
}
catch
(
err
)
{
ctx
.
status
=
401
;
ctx
.
body
=
{
code
:
401
,
message
:
'token失效或解析错误'
,
data
:
null
}
}
}
};
}
app/middleware/jwt.ts
deleted
100644 → 0
View file @
f7f1ec72
import
{
Context
,
EggAppConfig
}
from
'egg'
;
export
default
function
jwt
(
options
:
EggAppConfig
[
'jwt'
])
{
return
async
(
ctx
:
Context
,
next
:()
=>
Promise
<
any
>
)
=>
{
const
token
=
ctx
.
request
.
headers
.
authorization
;
if
(
token
)
{
try
{
ctx
.
app
.
jwt
.
verify
(
token
,
options
.
secret
);
await
next
();
}
catch
(
error
)
{
ctx
.
status
=
401
;
ctx
.
body
=
{
message
:
error
.
message
,
};
return
;
}
}
else
{
ctx
.
status
=
401
;
ctx
.
body
=
{
message
:
'没有token'
,
};
return
;
}
};
}
app/router.ts
View file @
59d498c9
import
{
Application
}
from
'egg'
;
import
{
Application
}
from
'egg'
;
import
socketRouter
from
'./socket-router'
;
import
socketRouter
from
'./socket-router'
;
import
authRouter
from
'./router/auth'
;
export
default
(
app
:
Application
)
=>
{
export
default
(
app
:
Application
)
=>
{
// const jwt = app.middleware.jwt(app.config.jwt);
// const jwt = app.middleware.jwt(app.config.jwt);
socketRouter
(
app
);
socketRouter
(
app
);
authRouter
(
app
)
// app.post('/login', controller.socket.login);
// app.post('/login', controller.socket.login);
// app.post('/createRoom', jwt, controller.socket.createRoom);
// app.post('/createRoom', jwt, controller.socket.createRoom);
// app.post('/joinRoom', jwt, controller.socket.joinRoom);
// app.post('/joinRoom', jwt, controller.socket.joinRoom);
...
...
app/router/auth.ts
0 → 100644
View file @
59d498c9
import
{
Application
}
from
"egg"
;
export
default
(
app
:
Application
)
=>
{
const
{
controller
}
=
app
app
.
get
(
'/login'
,
controller
.
auth
.
login
)
app
.
get
(
'/userInfo'
,
controller
.
auth
.
getUserInfo
)
};
\ No newline at end of file
config/config.default.ts
View file @
59d498c9
import
{
Context
,
EggAppConfig
,
EggAppInfo
,
PowerPartial
,
Request
}
from
'egg'
;
import
{
Context
,
EggAppConfig
,
EggAppInfo
,
PowerPartial
}
from
'egg'
;
import
*
as
qs
from
'qs'
;
//
import * as qs from 'qs';
export
default
(
appInfo
:
EggAppInfo
)
=>
{
export
default
(
appInfo
:
EggAppInfo
)
=>
{
const
config
=
{}
as
PowerPartial
<
EggAppConfig
>
;
const
config
=
{}
as
PowerPartial
<
EggAppConfig
>
;
config
.
keys
=
appInfo
.
name
+
'_1607088260928_8707'
;
config
.
keys
=
appInfo
.
name
+
'_1607088260928_8707'
;
config
.
middleware
=
[];
config
.
middleware
=
[
'auth'
];
config
.
routerNotAuth
=
[
'/login'
,
'/register'
]
const
bizConfig
=
{
const
bizConfig
=
{
sourceUrl
:
'https://geek.jkwljy.com/'
,
sourceUrl
:
'https://geek.jkwljy.com/'
,
...
@@ -16,24 +19,6 @@ export default (appInfo: EggAppInfo) => {
...
@@ -16,24 +19,6 @@ export default (appInfo: EggAppInfo) => {
'.nj'
:
'nunjucks'
,
'.nj'
:
'nunjucks'
,
},
},
};
};
// const redis = {
// host: '192.168.32.32',
// port: 6379,
// };
const
io
=
{
init
:
{
wsEngine
:
'ws'
},
namespace
:
{
'/'
:
{
connectionMiddleware
:
[
'auth'
],
// 通常在这一步进行授权认证,对认证失败的客户端做出相应的处理
packetMiddleware
:
[
'packet'
],
// 针对消息的处理
},
},
generateId
:
(
req
:
Request
)
=>
{
// 自定义 socket.id 生成函数
const
data
=
qs
.
parse
(
req
.
url
.
split
(
'?'
)[
1
]);
return
data
.
userId
||
new
Date
().
getTime
().
toFixed
(
0
);
},
// redis,
};
const
cors
=
{
const
cors
=
{
origin
:
'*'
,
origin
:
'*'
,
...
@@ -63,7 +48,7 @@ export default (appInfo: EggAppInfo) => {
...
@@ -63,7 +48,7 @@ export default (appInfo: EggAppInfo) => {
...
config
,
...
config
,
...
bizConfig
,
...
bizConfig
,
view
,
view
,
io
,
//
io,
jwt
,
jwt
,
cors
,
cors
,
onerror
,
onerror
,
...
...
typings/app/controller/index.d.ts
View file @
59d498c9
// This file is created by egg-ts-helper@1.25.
8
// This file is created by egg-ts-helper@1.25.
9
// Do not modify this file!!!!!!!!!
// Do not modify this file!!!!!!!!!
import
'egg'
;
import
'egg'
;
import
ExportAuth
from
'../../../app/controller/auth'
;
import
ExportSocket
from
'../../../app/controller/socket'
;
import
ExportSocket
from
'../../../app/controller/socket'
;
declare
module
'egg'
{
declare
module
'egg'
{
interface
IController
{
interface
IController
{
auth
:
ExportAuth
;
socket
:
ExportSocket
;
socket
:
ExportSocket
;
}
}
}
}
typings/app/extend/helper.d.ts
View file @
59d498c9
// This file is created by egg-ts-helper@1.25.
8
// This file is created by egg-ts-helper@1.25.
9
// Do not modify this file!!!!!!!!!
// Do not modify this file!!!!!!!!!
import
'egg'
;
import
'egg'
;
...
...
typings/app/index.d.ts
View file @
59d498c9
// This file is created by egg-ts-helper@1.25.
8
// This file is created by egg-ts-helper@1.25.
9
// Do not modify this file!!!!!!!!!
// Do not modify this file!!!!!!!!!
import
'egg'
;
import
'egg'
;
...
...
typings/app/middleware/index.d.ts
View file @
59d498c9
// This file is created by egg-ts-helper@1.25.
8
// This file is created by egg-ts-helper@1.25.
9
// Do not modify this file!!!!!!!!!
// Do not modify this file!!!!!!!!!
import
'egg'
;
import
'egg'
;
import
Export
Jwt
from
'../../../app/middleware/jwt
'
;
import
Export
Auth
from
'../../../app/middleware/auth
'
;
declare
module
'egg'
{
declare
module
'egg'
{
interface
IMiddleware
{
interface
IMiddleware
{
jwt
:
typeof
ExportJwt
;
auth
:
typeof
ExportAuth
;
}
}
}
}
typings/app/model/index.d.ts
View file @
59d498c9
// This file is created by egg-ts-helper@1.25.
8
// This file is created by egg-ts-helper@1.25.
9
// Do not modify this file!!!!!!!!!
// Do not modify this file!!!!!!!!!
import
'egg'
;
import
'egg'
;
...
...
typings/app/service/index.d.ts
View file @
59d498c9
// This file is created by egg-ts-helper@1.25.
8
// This file is created by egg-ts-helper@1.25.
9
// Do not modify this file!!!!!!!!!
// Do not modify this file!!!!!!!!!
import
'egg'
;
import
'egg'
;
...
...
typings/config/index.d.ts
View file @
59d498c9
// This file is created by egg-ts-helper@1.25.
8
// This file is created by egg-ts-helper@1.25.
9
// Do not modify this file!!!!!!!!!
// Do not modify this file!!!!!!!!!
import
'egg'
;
import
'egg'
;
...
...
typings/config/plugin.d.ts
View file @
59d498c9
// This file is created by egg-ts-helper@1.25.
8
// This file is created by egg-ts-helper@1.25.
9
// Do not modify this file!!!!!!!!!
// Do not modify this file!!!!!!!!!
import
'egg'
;
import
'egg'
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment