Inject API host into the javascript (hack again)

This commit is contained in:
Brandon Thomas committed 2016-11-06 05:16:59 -05:00
1 parent 5c6cd281c4
commit ccfbefddd1
3 files changed
+21 -2

No files matched your search

+18 -2
View File
@@ -1,16 +1,32 @@
// Copyright (c) 2016 Brandon Thomas <bt@brand.io, echelon@gmail.com>
import $ = require('jquery');
import { RawSentence, FilteredSentence } from "./sentence";
import URI = require('urijs');
/**
* The API server hostname (including HTTP scheme).
* This is injected into the meta tags before upload so we can build the path.
*/
function getApiHost(): string {
let environment = $('meta[name=environment]').attr('content');
switch (environment.toLowerCase()) {
case 'production':
return $('meta[name=api_host]').attr('content');
default:
return '';
}
}
/**
* Sentence -> Audio generation API URL
*/
export function get_audio_api_url(sentence: FilteredSentence) : string {
// I may expand the API later, but for now this is all I'll expose.
let encoded = encodeURIComponent(sentence.value);
return `/speak?v=trump&vol=3&s=${encoded}`;
let apiHost = getApiHost(),
encoded = encodeURIComponent(sentence.value);
return `${apiHost}/speak?v=trump&vol=3&s=${encoded}`;
}
/**
+2
View File
@@ -36,8 +36,10 @@ pushd $output_dir > /dev/null
sed -i "s/assets\/output/assets/g" index.html
# /assets/main.built.js -> //cdn.junglehorse.com/assets/${checksum}/main.built.js
sed -i "s/\/assets/\/\/cdn.junglehorse.com\/assets\/${checksum}/g" index.html
# Variable substitutions
sed -i "s/asset_content_hash/${checksum}/g" index.html
sed -i "s/DEVELOPMENT/production/g" index.html
sed -i "s/API_HOST/http:\/\/jungle.horse/g" index.html
popd > /dev/null
echo "> Upload to S3."
+1
View File
@@ -10,6 +10,7 @@
<link href="https://fonts.googleapis.com/css?family=Fira+Sans" rel="stylesheet">
<meta name="content_hash" content="asset_content_hash">
<meta name="environment" content="DEVELOPMENT">
<meta name="api_host" content="API_HOST">
</head>
<body>
<div id="animation"></div>