remove api directory, remove redeploy action

This commit is contained in:
Matthias Kretschmann 2020-07-20 22:16:59 +02:00
parent 69f8a091d8
commit cb4850835d
Signed by: m
GPG Key ID: 606EEEF3C479A91F
6 changed files with 3 additions and 82 deletions

View File

@ -13,7 +13,6 @@
- [🤓 Resources](#-resources)
- [🏄 Get Started](#-get-started)
- [Local Spree components with Barge](#local-spree-components-with-barge)
- [API](#api)
- [🦑 Environment variables](#-environment-variables)
- [🎨 Storybook](#-storybook)
- [✨ Code Style](#-code-style)
@ -73,12 +72,6 @@ Finally, set environment variables to use those local connections in `.env` in t
cp .env.example .env
```
### API
Files under `/api` are isolated and not part of Gatsby.
- [API Documentation](api/)
## 🦑 Environment variables
The `app.config.js` file is setup to prioritize environment variables for setting each Ocean component endpoint. By setting environment variables, you can easily switch between Ocean networks the app connects to, without directly modifying `app.config.js`.

View File

@ -1,31 +0,0 @@
import { NowRequest, NowResponse } from '@vercel/node'
import axios, { AxiosResponse } from 'axios'
import siteConfig from '../content/site.json'
async function redeploy(
req: NowRequest
): Promise<AxiosResponse | undefined | string> {
// Cancel if we are not on live
if (req.headers.host !== siteConfig.site.siteUrl) return ''
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)
}
}
export default async (req: NowRequest, res: NowResponse) => {
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`)
}
}

View File

@ -1,7 +1,6 @@
import React, { useState, useEffect } from 'react'
import React, { useState, useEffect, ReactElement } from 'react'
import { useNavigate } from '@reach/router'
import { DDO } from '@oceanprotocol/lib'
import { redeploy } from '../../utils'
import Button from '../atoms/Button'
import BaseDialog from '../atoms/BaseDialog'
import { useOcean } from '@oceanprotocol/react'
@ -13,7 +12,7 @@ const content = [
'Something happened... Your Data Set cannot be deleted'
]
export default function DeleteAction({ ddo }: { ddo: DDO }) {
export default function DeleteAction({ ddo }: { ddo: DDO }): ReactElement {
const { ocean, accountId } = useOcean()
const navigate = useNavigate()
const isOwner = ddo.publicKey[0].owner === accountId
@ -42,9 +41,6 @@ export default function DeleteAction({ ddo }: { ddo: DDO }) {
const consumerAddress = (await ocean.accounts.list())[0]
await ocean.assets.retire(ddo.id, consumerAddress)
// trigger new live deployment
await redeploy()
setStatus(2)
} catch (error) {
// TODO: handle error

View File

@ -139,12 +139,3 @@ export function formatBytes(a: number, b: number): string {
const f = Math.floor(Math.log(a) / Math.log(c))
return parseFloat((a / Math.pow(c, f)).toFixed(d)) + ' ' + e[f]
}
export async function redeploy(): Promise<AxiosResponse | undefined> {
try {
const response = await axios.post('/api/redeploy')
return response
} catch (err) {
console.error(err.message)
}
}

View File

@ -1,28 +0,0 @@
import { createMocks } from 'node-mocks-http'
import apiRoute from '../../../api/file'
describe('/api/file', () => {
test('responds 405 to GET', async () => {
const { req, res } = createMocks()
apiRoute(req, res)
expect(res._getStatusCode()).toBe(405)
})
test('responds 200 to POST', async () => {
const { req, res } = createMocks({ method: 'POST' })
apiRoute(req, res)
expect(res._getStatusCode()).toBe(200)
})
test('responds correctly to POST and url passed in body', async () => {
const { req, res } = createMocks({
method: 'POST',
body: {
url: 'https://oceanprotocol.com/tech-whitepaper.pdf'
}
})
apiRoute(req, res)
expect(res._getStatusCode()).toBe(200)
expect(res._getData()).toBeDefined()
})
})

View File

@ -16,5 +16,5 @@
"allowJs": true
},
"exclude": ["node_modules", "public", ".cache", "*.js"],
"include": ["./src/**/*", "./api/**/*", "./tests/**/*", "./app.config.js"]
"include": ["./src/**/*", "./tests/**/*", "./app.config.js"]
}