Today I Learned

2 posts by bartłomiejdudzik

ember-cli-mirage/miragejs passthrough random url

ember-cli-mirage

miragejs

While developing an app with mocks, sometimes We need to passthrough a certain url, so pretender can pass the request to the specified url, so what We’d do is simply

server.passthrough("https://domain.com/pass_here")
or
server.passthrough("https://domain.com/**")

to pass all requests to this domain. But what if We deal with aws lambdas which can have generated urls like here https://domain-<random-stuff>.com?

Up until recently, We couldn’t handle that, at least not so easily, but luckily an undocumented feature was added which allows for passthrough to take a function as argument which has to return either true to passthrough the request or false to be caught by pretender.

(function argument is allowed in ember-cli-mirage#1.1.4 and miragejs#0.1.31)

e.g server.passthrough((request) => request.url.includes("domain") Should handle pesky auto-generated urls.

Publishing private repository with public dependencies

Simply using https or ssh links in package.json can backfire for people who have or didn’t have used any additional security measures like 2FA or SSH.

https: "git+https://github.com/OWNER/REPO.git" - would fail when 2FA is set up, and would fail on token authorization. ssh: "git@github.com:OWNER/REPO.git" - obviously fails when no SSH key is defined. (Its recommended to have one)

So We decided to use Github Package Registry that allows you to easily publish public/private repos (currently GPR is in open beta). All instructions how to publish/install a package are here

create personal access token for CLI

installing a package

But the latter link, can be misleading. (Although is assuming that everyone in organization has their own PAT generated, which might be a much better solution).

When you setup your .npmrc with this config:

registry=https://npm.pkg.github.com/${OWNER}/:_authToken=${PERSONAL_ACCESS_TOKEN}

during npm install it will try to download any package’s dependency from your OWNER domain even though its dependencies are public.

So you can use a config like this to avoid having public dependencies published in your domain.

${OWNER}:registry=https://npm.pkg.github.com/
//npm.pkg.github.com/:_authToken=${PERSONAL_ACCESS_TOKEN}

e.g

@bobrimperator:registry=https://npm.pkg.github.com/
//npm.pkg.github.com/:_authToken=my-generated-token-with-read-permission

Further references: Setting up fontawesome pro in your project