1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-11-15 01:34:57 +01:00
market/api/redeploy.ts

32 lines
958 B
TypeScript
Raw Normal View History

2020-06-30 13:00:16 +02:00
import { NowRequest, NowResponse } from '@now/node'
2020-06-02 11:15:21 +02:00
import axios, { AxiosResponse } from 'axios'
2020-06-30 13:00:16 +02:00
import siteConfig from '../content/site.json'
2020-06-02 11:15:21 +02:00
async function redeploy(
2020-06-30 13:00:16 +02:00
req: NowRequest
2020-06-02 11:15:21 +02:00
): Promise<AxiosResponse | undefined | string> {
// Cancel if we are not on live
2020-06-30 13:00:16 +02:00
if (req.headers.host !== siteConfig.site.siteUrl) return ''
2020-06-02 11:15:21 +02:00
console.log('not canceled', req)
try {
// Trigger new `master` deployment with Deploy Hook
const newDeployment = await axios.post(
'https://api.zeit.co/v1/integrations/deploy/Qmd5YCS9PCCCqn4mjgVR3vGkYWNmEB5UnAzhnjZiGbMCKa/Q6viwRoT4V'
)
return newDeployment
} catch (error) {
console.error(error.message)
}
}
2020-06-30 13:00:16 +02:00
export default async (req: NowRequest, res: NowResponse) => {
2020-06-02 11:15:21 +02:00
switch (req.method) {
case 'POST':
res.status(200).json(await redeploy(req))
break
default:
res.setHeader('Allow', ['POST'])
res.status(405).end(`Method ${req.method} Not Allowed`)
}
}