Skip to content

Commit

Permalink
feat: insert ta init script when start scheduler (#2283)
Browse files Browse the repository at this point in the history
  • Loading branch information
daskyrk authored Dec 13, 2021
1 parent 8a6e88e commit f7f13ef
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
22 changes: 20 additions & 2 deletions scheduler/src/filters/not-found.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,30 @@ if (!fs.existsSync(indexHtmlPath)) {
const indexHtmlContent = fs.readFileSync(indexHtmlPath, { encoding: 'utf8' });
const newIndexHtmlPath = path.join(staticDir, 'shell', 'index-new.html');

const { UC_PUBLIC_URL = '', ENABLE_BIGDATA = '', ENABLE_EDGE = '' } = process.env;
const {
UC_PUBLIC_URL = '',
ENABLE_BIGDATA = '',
ENABLE_EDGE = '',
TERMINUS_KEY = '',
TERMINUS_TA_ENABLE = false,
TERMINUS_TA_URL = '',
TERMINUS_TA_COLLECTOR_URL = '',
} = process.env;

const newContent = indexHtmlContent.replace(
let newContent = indexHtmlContent.replace(
'<!-- $ -->',
`<script>window.erdaEnv={UC_PUBLIC_URL:"${UC_PUBLIC_URL}",ENABLE_BIGDATA:"${ENABLE_BIGDATA}",ENABLE_EDGE:"${ENABLE_EDGE}"}</script>`,
);
if (TERMINUS_TA_ENABLE) {
const taContent = `
<script>
var _taConfig = window._taConfig;
!function(e,n,r,t,a,o,c){e[a]=e[a]||function(){(e[a].q=e[a].q||[]).push(arguments)},e.onerror=function(n,r,t,o,c){e[a]("sendExecError",n,r,t,o,c)},n.addEventListener("error",function(n){e[a]("sendError",n)},!0),o=n.createElement(r),c=n.getElementsByTagName(r)[0],o.async=1,o.src=t,c.parentNode.insertBefore(o,c)}(window,document,"script",${TERMINUS_TA_URL},"$ta");
$ta('start', { udata: { uid: 0 }, ak: ${TERMINUS_KEY}, url: ${TERMINUS_TA_COLLECTOR_URL}, ck: true });
</script>
`;
newContent = indexHtmlContent.replace('<!-- $ta -->', taContent);
}
fs.writeFileSync(newIndexHtmlPath, newContent, { encoding: 'utf8' });

@Catch(NotFoundException)
Expand Down
11 changes: 1 addition & 10 deletions shell/app/views/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,7 @@
<style type="text/css">
<%=htmlWebpackPlugin.options.css %>
</style>
<%if(htmlWebpackPlugin.options.isProd) {%>
<script src="/ta"></script>
<script>
var _taConfig = window._taConfig;
if (_taConfig && _taConfig.enabled) {
!function(e,n,r,t,a,o,c){e[a]=e[a]||function(){(e[a].q=e[a].q||[]).push(arguments)},e.onerror=function(n,r,t,o,c){e[a]("sendExecError",n,r,t,o,c)},n.addEventListener("error",function(n){e[a]("sendError",n)},!0),o=n.createElement(r),c=n.getElementsByTagName(r)[0],o.async=1,o.src=t,c.parentNode.insertBefore(o,c)}(window,document,"script",_taConfig.url,"$ta");
$ta('start', { udata: { uid: 0 }, ak: _taConfig.ak, url: _taConfig.collectorUrl, ck: true });
}
</script>
<%}%>
<!-- $ta -->
</head>
<body>
Expand Down

0 comments on commit f7f13ef

Please sign in to comment.