9eff69be75
* /dream api: Upload StableDiffusion image to Firestore * Minor tweaks * Set content type on uploaded image This makes it so the image doesn't auto-download when opened in a new tab * Allow users to dream directly from within Manifold * Remove unused import * Implement a /comment endpoint which supports html and markdown * Upgrade @tiptap/core to latest * Update all tiptap deps to beta.199 * Add @tiptap/suggestion * Import @tiptap/html in the right place * ... add deps everywhere So I have no idea how common deps work apparently * Add tiptap/suggestion too * Clean up dream * More cleanups * Rework /comment endpoint * Move API to /comment * Change imports in case that matters * Add a couple todos * Dynamically import micromark * Parallellize gsutil with -m option * Adding comments via api working, editor.tsx erroring out * Unused import * Remove disabled state from useTextEditor Co-authored-by: Ian Philips <iansphilips@gmail.com>
78 lines
3.2 KiB
TypeScript
78 lines
3.2 KiB
TypeScript
import * as cors from 'cors'
|
|
import * as express from 'express'
|
|
import { Express, Request, Response, NextFunction } from 'express'
|
|
import { EndpointDefinition } from './api'
|
|
|
|
const PORT = 8088
|
|
|
|
import { initAdmin } from './scripts/script-init'
|
|
initAdmin()
|
|
|
|
import { health } from './health'
|
|
import { transact } from './transact'
|
|
import { changeuserinfo } from './change-user-info'
|
|
import { createuser } from './create-user'
|
|
import { createanswer } from './create-answer'
|
|
import { placebet } from './place-bet'
|
|
import { cancelbet } from './cancel-bet'
|
|
import { sellbet } from './sell-bet'
|
|
import { sellshares } from './sell-shares'
|
|
import { claimmanalink } from './claim-manalink'
|
|
import { createmarket } from './create-market'
|
|
import { createcomment } from './create-comment'
|
|
import { creategroup } from './create-group'
|
|
import { resolvemarket } from './resolve-market'
|
|
import { unsubscribe } from './unsubscribe'
|
|
import { stripewebhook, createcheckoutsession } from './stripe'
|
|
import { getcurrentuser } from './get-current-user'
|
|
import { createpost } from './create-post'
|
|
import { savetwitchcredentials } from './save-twitch-credentials'
|
|
import { testscheduledfunction } from './test-scheduled-function'
|
|
import { addcommentbounty, awardcommentbounty } from './update-comment-bounty'
|
|
|
|
type Middleware = (req: Request, res: Response, next: NextFunction) => void
|
|
const app = express()
|
|
|
|
const addEndpointRoute = (
|
|
path: string,
|
|
endpoint: EndpointDefinition,
|
|
...middlewares: Middleware[]
|
|
) => {
|
|
const method = endpoint.opts.method.toLowerCase() as keyof Express
|
|
const corsMiddleware = cors({ origin: endpoint.opts.cors })
|
|
const allMiddleware = [...middlewares, corsMiddleware]
|
|
app.options(path, corsMiddleware) // preflight requests
|
|
app[method](path, ...allMiddleware, endpoint.handler)
|
|
}
|
|
|
|
const addJsonEndpointRoute = (name: string, endpoint: EndpointDefinition) => {
|
|
addEndpointRoute(name, endpoint, express.json())
|
|
}
|
|
|
|
addEndpointRoute('/health', health)
|
|
addJsonEndpointRoute('/transact', transact)
|
|
addJsonEndpointRoute('/changeuserinfo', changeuserinfo)
|
|
addJsonEndpointRoute('/createuser', createuser)
|
|
addJsonEndpointRoute('/createanswer', createanswer)
|
|
addJsonEndpointRoute('/createcomment', createcomment)
|
|
addJsonEndpointRoute('/placebet', placebet)
|
|
addJsonEndpointRoute('/cancelbet', cancelbet)
|
|
addJsonEndpointRoute('/sellbet', sellbet)
|
|
addJsonEndpointRoute('/sellshares', sellshares)
|
|
addJsonEndpointRoute('/claimmanalink', claimmanalink)
|
|
addJsonEndpointRoute('/createmarket', createmarket)
|
|
addJsonEndpointRoute('/addCommentBounty', addcommentbounty)
|
|
addJsonEndpointRoute('/awardCommentBounty', awardcommentbounty)
|
|
addJsonEndpointRoute('/creategroup', creategroup)
|
|
addJsonEndpointRoute('/resolvemarket', resolvemarket)
|
|
addJsonEndpointRoute('/unsubscribe', unsubscribe)
|
|
addJsonEndpointRoute('/createcheckoutsession', createcheckoutsession)
|
|
addJsonEndpointRoute('/getcurrentuser', getcurrentuser)
|
|
addJsonEndpointRoute('/savetwitchcredentials', savetwitchcredentials)
|
|
addEndpointRoute('/stripewebhook', stripewebhook, express.raw())
|
|
addEndpointRoute('/createpost', createpost)
|
|
addEndpointRoute('/testscheduledfunction', testscheduledfunction)
|
|
|
|
app.listen(PORT)
|
|
console.log(`Serving functions on port ${PORT}.`)
|