How to set cross-domain settings for egg when the front and rear ends are separated

the front-end url is in the format of
http://localhost:3333/index.html-sharp/detail
accesses the backend and reports a cross-domain error
No "Access-Control-Allow-Origin" header is present on the requested resource.. Origin" http://localhost:3333" is therefore not allowed access.
how to configure the backend whitelist in
config.default.js:
http://localhost:3333/index.html-sharp/detail
is still invalid. If you can"t think of a sister, ask for advice!


instead of setting the whitelist, just specify the access domain name and enable the authentication mode in the origin configured by the egg cross-domain plug-in

//config.js
config.cors = {
    origin:'http://ip:port',
    credentials: true,
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH'
  };

Open cors

egg-cors Link description

Menu