My webpage creates a new script element and then loads the script from a localhost server. The problem is that the script cannot be loaded and shows PROTOCOL ERROR:
https://localhost:4200/script/test.js net::ERR_SSL_PROTOCOL_ERROR
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link href="./public/nps.style.css" rel="stylesheet" />
<script>
j = document.getElementsByTagName('script')[0],
k = document.createElement('script');
k.src = 'http://localhost:4200/script/test.js';
j.parentNode.insertBefore(k,j);
</script>
</head>
<body>
<p>Testing</p>
</body>
</html>
Then create a localhost server to listen it so the JavaScript file can be downloaded
index.js:
const express = require('express');
const cors = require('cors');
const { test } = require('./script/test.js');
const api = express();
api.use(cors({origin: '*'}));
api.use('/script', express.static('public'));
api.listen(4200, () => {
console.log("Server listening");
})
test.js:
alert("it works!");
How can I solve this issue?
Update:
Initially I had the source of the new script element as 'https://localhost:4200/script/test.js', So I changed to http, a new error occurred:
GET http://localhost:4200/script/test.js net::ERR_ABORTED 404 (Not Found)
