Embed string variables into EJS

I am trying to embed some strings and urls from JS into an EJS file.

The idea is that we have an application on 3 environments, dev, test and production.
For every environment, the application is accessed via 3 urls:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>appserver.com/app
appserver.com/testapp
appserver.com/devapp
</code>
<code>appserver.com/app appserver.com/testapp appserver.com/devapp </code>
appserver.com/app
appserver.com/testapp
appserver.com/devapp

Also, all resources (css, js, images) are accessed using /app, /testapp and /devapp, based on the machine the app is on.

For this, I created a JS file, called environment.js with a few functions that return the desired urls and string.
For example, it contains one function called returnCurrentSite that returns “app”, “testapp” or “devapp”, based on the value of a switch variable.

I also have a header.ejs file that contains the links to libraries and other resources:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><link rel="stylesheet" type="text/css" href="../app/css/bootstrap.min.css">
<link rel="stylesheet" href="/app/fonts/font-awesome-4.6.3/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="../app/css/general.css">
<script src="../app/library.js" type="text/javascript"></script>
</code>
<code><link rel="stylesheet" type="text/css" href="../app/css/bootstrap.min.css"> <link rel="stylesheet" href="/app/fonts/font-awesome-4.6.3/css/font-awesome.min.css"> <link rel="stylesheet" type="text/css" href="../app/css/general.css"> <script src="../app/library.js" type="text/javascript"></script> </code>
<link rel="stylesheet" type="text/css" href="../app/css/bootstrap.min.css">
<link rel="stylesheet" href="/app/fonts/font-awesome-4.6.3/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="../app/css/general.css">

<script src="../app/library.js" type="text/javascript"></script>

After that, I changed the header.ejs so that instead of “app” to have the value returned by the JS function:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><link rel="stylesheet" type="text/css" href="../<%= returnCurrentSite() %>/css/bootstrap.min.css">
<script src="../<%= returnCurrentSite() %>/library.js" type="text/javascript"></script>
</code>
<code><link rel="stylesheet" type="text/css" href="../<%= returnCurrentSite() %>/css/bootstrap.min.css"> <script src="../<%= returnCurrentSite() %>/library.js" type="text/javascript"></script> </code>
<link rel="stylesheet" type="text/css" href="../<%= returnCurrentSite() %>/css/bootstrap.min.css">
<script src="../<%= returnCurrentSite() %>/library.js" type="text/javascript"></script>

The “header.ejs” file is included in every other EJS file using <%- include('partials/header.ejs') %>

So far so good. The problem is, whenever I access any EJS file, instead of having the urls as expected, I get something like this:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><link rel="stylesheet" type="text/css" href="..//css/bootstrap.min.css">
<script src="..//library.js" type="text/javascript"></script>
</code>
<code><link rel="stylesheet" type="text/css" href="..//css/bootstrap.min.css"> <script src="..//library.js" type="text/javascript"></script> </code>
<link rel="stylesheet" type="text/css" href="..//css/bootstrap.min.css">
<script src="..//library.js" type="text/javascript"></script>

I tried to store the returned vallue into a variable and use the variable instead of the function (<%= currentSite %>) but with same result.

I did find some examples online like this and for some this seamed to be working.

I also get a lot of errors and I’m a bit stuck:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' nonce-9b858e6c55a67d8f". Either the 'unsafe-inline' keyword, a hash ('sha256-FyXf4vQdaZjSdIl0NS/E4M/csa+Ko73WchX2nTsWFH4='), or a nonce ('nonce-...') is required to enable inline execution.
</code>
<code>Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' nonce-9b858e6c55a67d8f". Either the 'unsafe-inline' keyword, a hash ('sha256-FyXf4vQdaZjSdIl0NS/E4M/csa+Ko73WchX2nTsWFH4='), or a nonce ('nonce-...') is required to enable inline execution. </code>
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' nonce-9b858e6c55a67d8f". Either the 'unsafe-inline' keyword, a hash ('sha256-FyXf4vQdaZjSdIl0NS/E4M/csa+Ko73WchX2nTsWFH4='), or a nonce ('nonce-...') is required to enable inline execution.

I understand that this is a result of the Content Security Policy (https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) but I’m not really sure how to fix this in my case.

Any suggestions? Or maybe a better way to approach this?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật