UNPKG

@muban/storybook

Version:
26 lines (25 loc) 1.48 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; export function fetchStoryHtmlUsingPostJson(url, path, parameters, storyContext) { return __awaiter(this, void 0, void 0, function* () { const fetchUrl = new URL(`${url}/${path}`, 'http://fallback'); const response = yield fetch(fetchUrl.toString().replace('http://fallback', ''), { method: 'POST', headers: { // eslint-disable-next-line @typescript-eslint/naming-convention Accept: 'text/html', // eslint-disable-next-line @typescript-eslint/naming-convention 'Content-Type': 'application/json', }, body: JSON.stringify(Object.assign(Object.assign({}, storyContext.globals), { templateData: parameters })), }); return response.text(); }); }