I deleted all CSP-related files from index.html. I added a few changes to the server.js file and "Not Found" disappeared, but I ran into "Cannot GET / path" problem. I found the answer here Angular 2: 404 error occur when I refresh through the browser
Below I put the files that have been changed:
"name": "surveyjs-angular-cli",
"version": "1.1.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"postinstall": "ng build --aot",
"start": "node server.js",
"lint": "ng lint",
"e2e": "ng e2e"
},
app.module
import { HashLocationStrategy, LocationStrategy } from '@angular/common';
@NgModule({
declarations: [
AppComponent,
SurveyComponent,
MyOtherComponents
HomePageComponent,
],
imports: [BrowserModule, FormsModule, HttpClientModule, AppRoutingModule],
providers: [{provide: LocationStrategy, useClass: HashLocationStrategy}],
exports: [AppComponent, SurveyComponent, BrowserModule, FormsModule],
bootstrap: [AppComponent],
})
export class AppModule {}
index.html
<html class="image">
<head>
<title>Title</title>
<base href="/" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="https://cdn.ckeditor.com/4.5.1/standard/ckeditor.js"></script>
<script src="https://cdn.rawgit.com/inexorabletash/polyfill/master/typedarray.js"></script>
<script src="https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js"></script>
</head>
<body>
<app-root>Loading...</app-root>
</body>
</html>
server.js
const express = require('express');
const path = require('path');
const app = express();
// Serve only the static files form the dist directory
app.use(express.static('./dist'));
app.get('', function(req, res) {
res.sendFile(path.join(__dirname, '/dist/', 'index.html'));
});
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname, '/dist/', 'index.html'));
});
// Start the app by listening on the default Heroku port
app.listen(process.env.PORT || 8090);
The key was to add this:
providers: [{provide: LocationStrategy, useClass: HashLocationStrategy}],
Credit to @granty for his contribution.