Skip to content
This repository has been archived by the owner on Apr 9, 2019. It is now read-only.

Refused to apply style from 'http://localhost:7001/umi.css' #2

Open
kennylbj opened this issue Sep 28, 2018 · 4 comments
Open

Refused to apply style from 'http://localhost:7001/umi.css' #2

kennylbj opened this issue Sep 28, 2018 · 4 comments

Comments

@kennylbj
Copy link

kennylbj commented Sep 28, 2018

I am using egg-view-static to serve static html resource built by create-umi . The built files was located in app/public dir and the following errors occured when i start the egg server and visit http://localhost:7001.

Refused to apply style from 'http://localhost:7001/umi.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

Here is the configs:

// config/config.default.js
module.exports = appInfo => {
  const config = exports = {};

  config.keys = appInfo.name + '12345';

  config.view = {
    defaultViewEngine: 'static',
    mapping: {
      '.html': 'static',
    },
  }

  config.security = {
    csrf: false,
  };

  return config;
};
// config/plugin.js
exports.viewStatic = {
  enable: true,
  package: 'egg-view-static',
};

Is there something i miss?

@okoala
Copy link

okoala commented Sep 28, 2018

demo please.

@atian25
Copy link
Member

atian25 commented Sep 28, 2018

you must change the relate path, because html is render as / path, not the file path app/public

so if you link some static resource, your should not use ./main.js but app/public/main.js

but if your path is /test maybe had to ../app/public/main.js

this lib is just a toy showcase.

@kennylbj
Copy link
Author

kennylbj commented Sep 28, 2018

Problem solved when I manually change all resources path from root to /public in public dir including lots of images path.

It's a lot weird to modify dist files built by front-end cli for serving static html in egg. Is there a clean way to serve html directly just like spring boot?

I know the best pratice for serving static file is to use static web server such as nginx cdn rather than node itself, but it's much convenint for developer to build tiny project if egg could support this feature.

@atian25
Copy link
Member

atian25 commented Sep 28, 2018

it's not an egg issue, but http server.

for now, if you don't care the visit url, just place all static file to app/public then user visit via http://host/public/index.html

or if you only need to serve static file, then change egg-static config to use / instead of /public.

this lib is just a showcase for how to render a static file as template at public dir.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants