Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically added assets prefix in the image URL - Ember-CLI #131

Open
mockey-jockey opened this issue Apr 16, 2019 · 2 comments
Open

Dynamically added assets prefix in the image URL - Ember-CLI #131

mockey-jockey opened this issue Apr 16, 2019 · 2 comments

Comments

@mockey-jockey
Copy link

mockey-jockey commented Apr 16, 2019

I am trying to load the app by using ember serve. Some of the images are not found error getting.
In CSS :

background-image: url(assets/images/image.svg);

its redirected to

http://localhost:4200/assets/assets/images/image.svg 404 (Not Found)

because in this URL two assets name added that's why the image is not found, I don't know where this asset added.

when adding '/' in the prefix of URL am able to see the image in the app.

background-image: url(/assets/images/image.svg);

its redirected to

http://localhost:4200/assets/images/image.svg - working fine

How to avoid two assets name without using '/' as a prefix for assets. Kindly help anyone pls...

@Charizard
Copy link

@mockey-jockey Please add your config.

@mockey-jockey
Copy link
Author

var localEnv = require('./local_environment');

module.exports = function (environment) {
  var ENV = {
    modulePrefix: '----------',
    environment: environment,
    rootURL: '/',
    baseURL: '/',
    locationType: 'auto',
    'ember-cli-mirage': {
      enabled: false
    }
  };

  // Local Properties
  try {
    Object.keys(localEnv.config).forEach(function (key) {
      ENV[key] = localEnv.config[key];
    });
  } catch (err) {
    console.log("config/local_environment.js not found");
  }

  //  Set cdnUrl property
  var a = ENV.featureFlags.cdn && ENV.featureFlags.cdn.xyz,
    b = ENV.featureFlags.cdn && ENV.featureFlags.cdn.xys;

  // Fetching Deployment ID to build output path
  if (process.argv.length) {
    let pathPrefix = a && a.enabled && a.pathPrefix || b && b.enabled && agentPortal.pathPrefix || '',
      checkForArg = `--output-path=dist/${pathPrefix}`,
      deploymentPath = process.argv.find(param => param.indexOf(checkForArg) !== -1),
      deploymentID = deploymentPath && deploymentPath.replace(checkForArg, `${pathPrefix}`) || "";

    if (deploymentID) {
      ENV.outputPath = deploymentID;
    }
  }

  if (a && a.enabled) {
    ENV.EmberENV.cdnUrl = a.url.replace("{deploymentPath}", ENV.outputPath ? `${ENV.outputPath}/` : "");
    ENV.EmberENV.assetUrl = a.webUrl.replace("{deploymentPath}", ENV.outputPath ? `${ENV.outputPath}/` : "");
  } else if (b && b.enabled) {
    ENV.EmberENV.cdnUrl = b.url.replace("{deploymentPath}", ENV.outputPath ? `${ENV.outputPath}/` : "");
    ENV.EmberENV.assetUrl = b.webUrl.replace("{deploymentPath}", ENV.outputPath ? `${ENV.outputPath}/` : "");
  } else {
    throw "Config Missing in local_environment.js";
  }
  console.log(`CDN URL => ${ENV.EmberENV.cdnUrl}`);
  console.log(`Non CDN Asset URL => ${ENV.EmberENV.assetUrl}`);

  if (environment === 'development') {
    // ENV.APP.LOG_RESOLVER = true;
    // ENV.APP.LOG_ACTIVE_GENERATION = true;
    // ENV.APP.LOG_TRANSITIONS = true;
    // ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
    // ENV.APP.LOG_VIEW_LOOKUPS = true;
  }

  if (environment === 'test') {
    // Testem prefers this...
    ENV.baseURL = '/';
    ENV.locationType = 'none';

    ENV['ember-cli-mirage'] = {
      enabled: true
    };

    // keep test console output quieter
    ENV.APP.LOG_ACTIVE_GENERATION = false;
    ENV.APP.LOG_VIEW_LOOKUPS = false;

    ENV.APP.rootElement = '#ember-testing';
    ENV.APP.autoboot = false;

    ENV.EmberENV.cdnUrl = "";
    ENV.EmberENV.assetUrl = "";
  }

  return ENV;
};

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

No branches or pull requests

2 participants