Skip to content

Instantly share code, notes, and snippets.

@simonespa
Created December 18, 2019 12:51
Show Gist options
  • Select an option

  • Save simonespa/9b73d61784856489a51603a95be45624 to your computer and use it in GitHub Desktop.

Select an option

Save simonespa/9b73d61784856489a51603a95be45624 to your computer and use it in GitHub Desktop.
User-Agent override test
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<title>User Agent Override</title>
</head>
<body>
<script>
axios({
method: 'GET',
url: 'http://127.0.0.1:8080/test',
headers: {
'User-Agent': 'CustomUserAgent/1.0'
}
}).then((response) => {
const { data } = response;
console.log(data);
}).catch((error) => {
console.log(error.message);
});
</script>
</body>
</html>
const axios = require('axios');
axios({
method: 'GET',
url: 'http://127.0.0.1:8080/test',
headers: {
'User-Agent': 'CustomUserAgent/1.0'
}
}).then((response) => {
const { data } = response;
console.log(data);
}).catch((error) => {
console.log(error.message);
});
const express = require('express')
const cors = require('cors');
const app = express()
const port = 8080
const corsOptions = {
optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204
}
app.use(cors(corsOptions));
app.get('/test', (request, response) => {
const { headers } = request;
response.json({ headers });
});
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment