Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@commercetools-backend/express
Advanced tools
Zero-config HTTP server as Express.js to facilitate development
Zero-config HTTP server as Express.js to facilitate development.
This package is primarily built for HTTP servers used by Custom Applications and it provides a set of components to facilitate the development of the HTTP server.
$ npm install --save @commercetools-backend/express
This Express.js middleware should be used to handle the authentication exchange between the server and the /proxy/forward-to
endpoint of the Merchant Center API Gateway.
You can read more about the "Proxy to External API" concepts here.
const {
createSessionMiddleware,
CLOUD_IDENTIFIERS,
} = require('@commercetools-backend/express');
app.use(
createSessionMiddleware({
audience: 'https://my-api-server.com',
issuer: CLOUD_IDENTIFIERS.GCP_EU,
})
);
app.use((request, response, next) => {
// `request.session` contains the useful information
});
audience
(string): The public-facing URL of your API server. The value should only contain the origin URL (protocol, hostname, port), the request path is inferred from the incoming request.
issuer
(string): Either a cloud identifier or a valid URL to the Merchant Center API Gateway. The cloud identifier maps to the Merchant Center API URL of the related cloud region.
gcp-au
: https://mc-api.australia-southeast1.gcp.commercetools.com
gcp-eu
: https://mc-api.europe-west1.gcp.commercetools.com
gcp-us
: https://mc-api.us-central1.gcp.commercetools.com
aws-fra
: https://mc-api.eu-central-1.aws.commercetools.com
aws-ohio
: https://mc-api.us-east-2.aws.commercetools.com
inferIssuer
(boolean): Determines whether the issuer should be inferred from the custom request HTTP header x-mc-api-cloud-identifier
which is sent by the Merchant Center API Gateway when forwarding the request. This might be useful in case the server is used in multiple regions.
jwks
(object): See options of jwks-rsa
.
If your HTTP server runs as a Serverless Function, the Express.js middleware should not be needed. Instead you can use the underlying function that does not require the next
callback.
Example for Google Cloud Functions
const {
createSessionAuthVerifier,
CLOUD_IDENTIFIERS,
} = require('@commercetools-backend/express');
const sessionAuthVerifier = createSessionAuthVerifier({
audience: 'https://my-api-server.com',
issuer: CLOUD_IDENTIFIERS.GCP_EU,
});
exports.handler = async function (request, response) {
try {
await sessionAuthVerifier(request, response);
} catch (error) {
response.status(401).send(JSON.stringify({ message: 'Unauthorized' }));
return;
}
// `request.session` contains the useful information
};
The same concept applies for serverless functions in other cloud providers.
FAQs
Zero-config HTTP server as Express.js to facilitate development
The npm package @commercetools-backend/express receives a total of 1,435 weekly downloads. As such, @commercetools-backend/express popularity was classified as popular.
We found that @commercetools-backend/express demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.