Created
October 29, 2019 03:41
-
-
Save jebai0521/a69877f56674f17ec3d07977a34e86c1 to your computer and use it in GitHub Desktop.
Loopback Redirect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const axios = require('axios'); | |
axios.get( | |
'http://localhost:3000/aaaa', | |
{maxRedirects: 0}) | |
.then( | |
response => { | |
console.log(response.response.status, response.headers.location); | |
} | |
) | |
.catch(err => { | |
console.log(err); | |
console.log(err.response.status, err.response.headers.location); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
module.exports = function(server) { | |
// Install a `/` route that returns server status | |
var router = server.loopback.Router(); | |
router.get('/', server.loopback.status()); | |
router.get('/aaaa', function(req, rsp) { | |
// rsp.send('888'); | |
rsp.redirect(302, '/bbbb'); | |
}); | |
router.get('/bbbb', function(req, rsp) { | |
rsp.send('666'); | |
}); | |
server.use(router); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment