genezio
Version:
Command line utility to interact with Genezio infrastructure.
65 lines (64 loc) • 2.08 kB
JavaScript
import axios from "./axios.js";
import { getAuthToken } from "../utils/accounts.js";
import { GENEZIO_NOT_AUTH_ERROR_MSG, UserError } from "../errors.js";
import { BACKEND_ENDPOINT } from "../constants.js";
import version from "../utils/version.js";
import { debugLogger } from "../utils/logging.js";
export async function createFrontendProject(genezioDomain, projectName, region, stage, routingRules) {
// Check if user is authenticated
const authToken = await getAuthToken();
if (!authToken) {
throw new UserError(GENEZIO_NOT_AUTH_ERROR_MSG);
}
const json = JSON.stringify({
genezioDomain,
projectName,
region,
stage,
routingRules,
});
const response = await axios({
method: "PUT",
url: `${BACKEND_ENDPOINT}/frontend`,
data: json,
headers: {
Authorization: `Bearer ${authToken}`,
"Accept-Version": `genezio-cli/${version}`,
},
maxContentLength: Infinity,
maxBodyLength: Infinity,
});
if (!response.data.domain) {
throw new UserError("Could not create frontend project");
}
return response.data.domain;
}
export async function createFrontendProjectV2(domainName, projectName, region, stage, paths, defaultPath, stack) {
// Check if user is authenticated
const authToken = await getAuthToken();
if (!authToken) {
throw new UserError(GENEZIO_NOT_AUTH_ERROR_MSG);
}
const body = {
domainName,
projectName,
region,
stage,
paths,
defaultPath,
stack,
};
debugLogger.debug(`Sending create frontend request: ${JSON.stringify(body)}`);
const response = await axios({
method: "PUT",
url: `${BACKEND_ENDPOINT}/v2/frontend`,
data: JSON.stringify(body),
headers: {
Authorization: `Bearer ${authToken}`,
"Accept-Version": `genezio-cli/${version}`,
},
maxContentLength: Infinity,
maxBodyLength: Infinity,
});
return response.data;
}