Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
221 views
in Technique[技术] by (71.8m points)

Hapijs web server + Angular routing failed to load runtime.js

I was hoping to get some help on setting up Hapijs to host an angular project with routing.
My Angular static files are inside a directory named public.
I have my hapijs file set up like this:

const Hapi = require('@hapi/hapi');
const Inert = require('@hapi/inert');
const Path = require('path');

const server = new Hapi.Server({
    port: 4200,
    host: 'localhost',
    routes: {
        files: {
            relativeTo: Path.join(__dirname, 'public'),
        }
    }
});

const provision = async () => {
    await server.register(Inert);

    server.route({
        method: 'GET',
        path: '/{param*}',
        handler: {
            file: 'index.html'
        }
    });

    await server.start();
    
    console.log('Server running at:', server.info.uri);
};

provision();

The problem I'm experiencing is whenever I'm browsing to the web server it manages to load index.html but fails to load the required angular models (runtime.js, polyfills.js, main-es2015.js) with the following error: Failed to load module script: The server responded with a non-JavaScript MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.

question from:https://stackoverflow.com/questions/65883180/hapijs-web-server-angular-routing-failed-to-load-runtime-js

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...