Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added required header for analytics.config.json #2810

Merged
merged 1 commit into from Apr 18, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion build-system/server.js
Expand Up @@ -23,6 +23,7 @@ var bodyParser = require('body-parser');
var clr = require('connect-livereload');
var finalhandler = require('finalhandler');
var path = require('path');
var url = require('url');
var request = require('request');
var serveIndex = require('serve-index');
var serveStatic = require('serve-static');
Expand Down Expand Up @@ -107,9 +108,18 @@ app.use('/min/', function(req, res) {

app.use(clr());

function setAMPAccessControlHeader(res, path) {
var curUrl = url.parse(path, true);
if (curUrl.pathname.indexOf('/examples.build/analytics.config.json') > 0) {
res.setHeader('AMP-Access-Control-Allow-Source-Origin',
'http://localhost:' + port);
}
}

paths.split(',').forEach(function(pth) {
// Serve static files that exist
app.use(serveStatic(path.join(process.cwd(), pth)));
app.use(serveStatic(path.join(process.cwd(), pth),
{setHeaders: setAMPAccessControlHeader}));
// Serve directory listings
app.use(serveIndex(path.join(process.cwd(), pth),
{'icons':true,'view':'details'}));
Expand Down