saleor-apps-redis_apl/apps/invoices/src/pages/api/register.ts

29 lines
759 B
TypeScript
Raw Normal View History

2023-02-07 19:25:36 +00:00
import { createAppRegisterHandler } from "@saleor/app-sdk/handlers/next";
import { saleorApp } from "../../../saleor-app";
const allowedUrlsPattern = process.env.ALLOWED_DOMAIN_PATTERN;
/**
* Required endpoint, called by Saleor to install app.
* It will exchange tokens with app, so saleorApp.apl will contain token
*/
export default createAppRegisterHandler({
apl: saleorApp.apl,
/**
* Prohibit installation from Saleors other than specified by the regex.
* Regex source is ENV so if ENV is not set, all installations will be allowed.
*/
allowedSaleorUrls: [
(url) => {
if (allowedUrlsPattern) {
const regex = new RegExp(allowedUrlsPattern);
return regex.test(url);
}
return true;
},
],
});