Skip to content

Instantly share code, notes, and snippets.

@nida-001
Created July 1, 2017 12:57
Show Gist options
  • Save nida-001/4054918cbac2a120ca89c8796490625a to your computer and use it in GitHub Desktop.
Save nida-001/4054918cbac2a120ca89c8796490625a to your computer and use it in GitHub Desktop.
AMP loginを試そうとしたときの残骸
<!doctype html>
<html amp>
<head>
<meta charset="utf-8">
<script async src="https://cdn.ampproject.org/v0.js"></script>
<!--
Additionally used AMP components must be imported in the header.
-->
<script async custom-template="amp-mustache" src="https://cdn.ampproject.org/v0/amp-mustache-0.1.js"></script>
<script async custom-element="amp-form" src="https://cdn.ampproject.org/v0/amp-form-0.1.js"></script>
<script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script>
<script async custom-element="amp-access" src="https://cdn.ampproject.org/v0/amp-access-0.1.js"></script>
<script async custom-element="amp-list" src="https://cdn.ampproject.org/v0/amp-list-0.1.js"></script>
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<script id="amp-access" type="application/json">
{
"authorization": "http://localhost:8080/authorization?rid=READER_ID&url=CANONICAL_URL&ref=DOCUMENT_REFERRER&_=RANDOM",
"noPingback": "true",
"login": {
"sign-in": "http://localhost:8080/login?rid=READER_ID&url=CANONICAL_URL",
"sign-out": "http://localhost:8080/logout"
},
"authorizationFallbackResponse": {
"error": true,
"loggedIn": false
}
}
</script>
</head>
<body>
<span amp-access="NOT loggedIn" role="button" tabindex="0" amp-access-hide>
<h2 class="m1">Please login to comment</h2>
<button on="tap:amp-access.login-sign-in" class="ampstart-btn mx1 mt1 caps">Login</button>
</span>
</body>
</html>
const http = require('http');
const server = http.createServer();
server.on('request', function(request, response) {
const headers = request.headers;
const method = request.method;
const url = request.url;
let body = [];
request.on('error', function(err) {
console.log('error');
console.log(err);
}).on('data', function(chunk) {
body.push(chunk);
}).on('end', function() {
body = Buffer.concat(body).toString();
response.on('error', function(err) {
console.error(err);
});
response.statusCode = 200;
response.setHeader('Content-Type', 'application/json');
response.setHeader("Access-Control-Allow-Origin", 'null');
response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
response.setHeader('Access-Control-Allow-Credentials', true);
response.setHeader('access-control-expose-headers', 'AMP-Access-Control-Allow-Source-Origin');
response.setHeader('amp-access-control-allow-source-origin', 'http://localhost:8000');
response.setHeader('amp-access-control-allow-source-origin', 'file://');
var responseBody = {
'loggedIn': true
};
response.write(JSON.stringify(responseBody));
response.end();
});
}).listen(8080);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment