From 72df6d0bb1193e9078c93c3b85546bac1254203d Mon Sep 17 00:00:00 2001 From: JesseTheRobot Date: Sun, 17 Dec 2023 21:04:28 +0000 Subject: [PATCH] feat: :sparkles: API: Add HttpServer entrypoint --- src/HttpServer.ts | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/HttpServer.ts diff --git a/src/HttpServer.ts b/src/HttpServer.ts new file mode 100644 index 0000000..c13fc06 --- /dev/null +++ b/src/HttpServer.ts @@ -0,0 +1,40 @@ +/* eslint-disable header/header */ +import { default as cors } from 'cors'; +import express from 'express'; + +import * as config from './config.js'; +import log from './log.js'; +import { arIoRouter } from './routes/ar-io.js'; +import { arnsRouter } from './routes/arns.js'; +import { dataRouter } from './routes/data/index.js'; +import { apolloServer } from './routes/graphql/index.js'; +import { openApiRouter } from './routes/openapi.js'; +import * as system from './system.js'; + +const app = express(); + +app.use( + cors({ + exposedHeaders: ['X-ArNS-Resolved-Id', 'X-ArNS-TTL-Seconds'], + }), +); + +app.use(arnsRouter); +app.use(openApiRouter); +app.use(arIoRouter); +app.use(dataRouter); + +// GraphQL +const apolloServerInstanceGql = apolloServer(system.db, { + introspection: true, + persistedQueries: false, +}); +apolloServerInstanceGql.start().then(() => { + apolloServerInstanceGql.applyMiddleware({ + app, + path: '/graphql', + }); + app.listen(config.PORT, () => { + log.info(`Listening on port ${config.PORT}`); + }); +});