a2d61a1daa
* twitch account linking; profile page twitch panel; twitch landing page * fix import * twitch logo * save twitch credentials cloud function * use user id instead of bot id, add manifold api endpoint * properly add function to index * Added support for new redirect Twitch auth. * Added clean error handling in case of Twitch link fail. * remove simulator * Removed legacy non-redirect Twitch auth code. Added "add bot to channel" button in user profile and relevant data to user type. * Removed unnecessary imports. * Fixed line endings. * Allow users to modify private user twitchInfo firestore object * Local dev on savetwitchcredentials function Co-authored-by: Phil <phil.bladen@gmail.com> Co-authored-by: Marshall Polaris <marshall@pol.rs>
75 lines
2.9 KiB
TypeScript
75 lines
2.9 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 { addliquidity } from './add-liquidity'
|
|
import { withdrawliquidity } from './withdraw-liquidity'
|
|
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'
|
|
|
|
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('/placebet', placebet)
|
|
addJsonEndpointRoute('/cancelbet', cancelbet)
|
|
addJsonEndpointRoute('/sellbet', sellbet)
|
|
addJsonEndpointRoute('/sellshares', sellshares)
|
|
addJsonEndpointRoute('/claimmanalink', claimmanalink)
|
|
addJsonEndpointRoute('/createmarket', createmarket)
|
|
addJsonEndpointRoute('/addliquidity', addliquidity)
|
|
addJsonEndpointRoute('/withdrawliquidity', withdrawliquidity)
|
|
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)
|
|
|
|
app.listen(PORT)
|
|
console.log(`Serving functions on port ${PORT}.`)
|