Skip to content
Open
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 frontend/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ <h5>响应</h5>
<script type="text/javascript">
const reqBtn = document.getElementById('requestBtn')
reqBtn.addEventListener('click', _ => {
// 3000端口的web页面去请求4000端口的api服务会跨域
axios.post('http://127.0.0.1:4000/api/task').then(res => {
// 搭建bff层时请求端口直接该为前端自身web服务的端口即可
axios.post('http://127.0.0.1:3000/api/task').then(res => {
console.log(res.data)
const resBox = document.getElementById('resBox')
resBox.innerText = JSON.stringify(res.data)
Expand Down
6 changes: 6 additions & 0 deletions frontend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ app.use(views(path.join(__dirname, './'), {extension: 'html'}))
console.log('router', router.get)
router.get('/', demo).get('/demo.html', demo)

// web服务的bff层
router.post('/api/task', async (ctx, next) => {
const res = await axios.post('http://127.0.0.1:4000/api/task')
ctx.body = res.data;
})

async function demo(ctx) {
await ctx.render('demo')
}
Expand Down