Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
node-devlop-rest-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
zhouzihao
node-devlop-rest-api
Commits
2a8508d6
Commit
2a8508d6
authored
Mar 26, 2020
by
zhouzihao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dev-允许跨域请求
parent
7fd4a0a9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
0 deletions
+10
-0
route.js
route.js
+10
-0
No files found.
route.js
View file @
2a8508d6
...
@@ -13,6 +13,16 @@ app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
...
@@ -13,6 +13,16 @@ app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended
:
true
extended
:
true
}));
}));
// 允许跨域请求
app
.
all
(
'
*
'
,
function
(
req
,
res
,
next
)
{
res
.
header
(
'
Access-Control-Allow-Origin
'
,
'
*
'
);
//Access-Control-Allow-Headers ,可根据浏览器的F12查看,把对应的粘贴在这里就行
res
.
header
(
'
Access-Control-Allow-Headers
'
,
'
Content-Type
'
);
res
.
header
(
'
Access-Control-Allow-Methods
'
,
'
*
'
);
res
.
header
(
'
Content-Type
'
,
'
application/json;charset=utf-8
'
);
next
();
});
// todo add route
// todo add route
// test api
// test api
...
...
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