Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tax_api
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
data_server
tax_api
Commits
be20a880
Commit
be20a880
authored
Mar 15, 2019
by
何娜
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delete index.js
parent
487a78ff
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
81 deletions
+0
-81
index.js
index.js
+0
-81
No files found.
index.js
deleted
100644 → 0
View file @
487a78ff
const
path
=
require
(
'path'
);
const
Koa
=
require
(
'koa'
);
const
convert
=
require
(
'koa-convert'
);
const
views
=
require
(
'koa-views'
);
const
koaStatic
=
require
(
'koa-static'
);
const
bodyParser
=
require
(
'koa-bodyparser'
);
var
cors
=
require
(
'koa-cors'
);
const
util
=
require
(
'util'
);
const
cleanLog
=
require
(
'./utils/cheanLog'
);
const
log
=
require
(
'./utils/log'
);
const
koaLogger
=
require
(
'koa-logger'
);
const
config
=
require
(
'./config'
);
const
routers
=
require
(
'./routers/index'
);
const
app
=
new
Koa
();
// app.use((ctx)=>{
// console.log(ctx.headers);
// })
app
.
use
(
cors
());
// 配置控制台日志中间件
app
.
use
(
koaLogger
());
// 配置ctx.body解析中间件
app
.
use
(
bodyParser
());
// 配置静态资源加载中间件
app
.
use
(
koaStatic
(
path
.
join
(
__dirname
,
'./public/'
)
));
app
.
use
(
async
(
ctx
,
next
)
=>
{
const
token
=
ctx
.
header
.
authorization
// 获取jwt
let
payload
;
if
(
token
)
{
try
{
payload
=
await
verify
(
token
.
split
(
' '
)[
1
],
secret
)
// // 解密,获取payload
console
.
log
(
'payload'
,
payload
);
console
.
log
(
ctx
.
path
)
if
(
config
.
authData
[
ctx
.
path
]){
if
(
!
config
.
authData
[
ctx
.
path
].
includes
(
payload
.
auth
)){
ctx
.
status
=
403
;
ctx
.
body
=
{
status
:
'无权限'
}
return
}
}
}
catch
(
err
){
console
.
log
(
err
)
}
}
await
next
()
})
// 配置服务端模板渲染引擎中间件
app
.
use
(
views
(
path
.
join
(
__dirname
,
'./views'
),
{
extension
:
'ejs'
}));
// 初始化路由中间件
app
.
use
(
routers
.
routes
()).
use
(
routers
.
allowedMethods
());
// 监听启动端口
app
.
listen
(
config
.
port
)
log
.
info
(
`the server is start at port
${
config
.
port
}
`
);
cleanLog
();
// console.log(`the server is start at port ${config.port}`);
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