mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2026-03-01 12:44:37 +00:00
42 lines
1.8 KiB
TypeScript
42 lines
1.8 KiB
TypeScript
import CONFIG from './config'
|
|
import { loggerPlugin } from './plugins/apolloLogger'
|
|
import createProxy from './proxy'
|
|
import createServer from './server'
|
|
|
|
async function main() {
|
|
const { httpServer } = await createServer({
|
|
plugins: [loggerPlugin],
|
|
})
|
|
const url = new URL(CONFIG.GRAPHQL_URI)
|
|
httpServer.listen({ port: url.port }, () => {
|
|
/* eslint-disable-next-line no-console */
|
|
console.log(`🚀 Server ready at http://localhost:${url.port}/`)
|
|
/* eslint-disable-next-line no-console */
|
|
console.log(`🚀 Subscriptions ready at ws://localhost:${url.port}/`)
|
|
})
|
|
|
|
if (CONFIG.PROXY_S3) {
|
|
/*
|
|
In a Docker environment, the `AWS_ENDPOINT` of the backend container would be `http://minio:9000` but this domain is not reachable from the Docker host.
|
|
Therefore, we forward the local port 9000 to "http://minio:9000." The backend can upload files to its own proxy `http://localhost:9000` and the returned file location is going to be accessible from the web frontend.
|
|
This behavior is only required in local development, not in production. Therefore, we put it behind a `CONFIG.PROXY_S3` feature flag.
|
|
*/
|
|
const target = new URL(CONFIG.PROXY_S3)
|
|
const proxy = createProxy(target)
|
|
const forwardedPort = target.port // target port and forwarded port must be the same
|
|
proxy.listen(forwardedPort, () => {
|
|
/* eslint-disable-next-line no-console */
|
|
console.log(`Simple HTTP proxy listening on port ${forwardedPort}`)
|
|
/* eslint-disable-next-line no-console */
|
|
console.log(`Proxying requests to ${target}`)
|
|
})
|
|
}
|
|
}
|
|
|
|
// eslint-disable-next-line promise/prefer-await-to-callbacks, @typescript-eslint/use-unknown-in-catch-callback-variable
|
|
main().catch((err) => {
|
|
/* eslint-disable-next-line no-console */
|
|
console.error('Failed to start server:', err)
|
|
process.exit(1)
|
|
})
|