From 7b88e6b7289968909f77fa403013f4d52a827efc Mon Sep 17 00:00:00 2001 From: Chris Wilkinson Date: Wed, 28 Aug 2024 12:40:28 +0100 Subject: [PATCH] Make it easier to evolve by removing a superfluous layer Refs #1834 --- src/index.ts | 141 +++++++++++++++++++++++++-------------------------- 1 file changed, 69 insertions(+), 72 deletions(-) diff --git a/src/index.ts b/src/index.ts index acf341d01..1a5dc937f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,6 @@ import { Effect, Layer } from 'effect' import * as C from 'fp-ts/lib/Console.js' import * as E from 'fp-ts/lib/Either.js' import { pipe } from 'fp-ts/lib/function.js' -import http from 'http' import { Redis } from 'ioredis' import Keyv from 'keyv' import * as L from 'logger-fp-ts' @@ -49,85 +48,83 @@ const sendMailEnv = match(env) })) .exhaustive() -const server = http.createServer( - app({ - ...loggerEnv, - allowSiteCrawlers: env.ALLOW_SITE_CRAWLERS, - authorInviteStore: new Keyv({ namespace: 'author-invite', store: createKeyvStore() }), - avatarStore: new Keyv({ namespace: 'avatar-store', store: createKeyvStore() }), - canConnectOrcidProfile: () => true, - canRequestReviews: () => true, - canSeeGatesLogo: true, - canUploadAvatar: () => true, - canUseSearchQueries: () => true, - cloudinaryApi: { cloudName: 'prereview', key: env.CLOUDINARY_API_KEY, secret: env.CLOUDINARY_API_SECRET }, - coarNotifyToken: env.COAR_NOTIFY_TOKEN, - coarNotifyUrl: env.COAR_NOTIFY_URL, - contactEmailAddressStore: new Keyv({ namespace: 'contact-email-address', store: createKeyvStore() }), - environmentLabel: env.ENVIRONMENT_LABEL, - fathomId: env.FATHOM_SITE_ID, - fetch: fetch.defaults({ - cachePath: 'data/cache', - headers: { - 'User-Agent': `PREreview (${env.PUBLIC_URL.href}; mailto:engineering@prereview.org)`, - }, - }), - formStore: new Keyv({ namespace: 'forms', store: createKeyvStore() }), - careerStageStore: new Keyv({ namespace: 'career-stage', store: createKeyvStore() }), - ghostApi: { - key: env.GHOST_API_KEY, +const expressServer = app({ + ...loggerEnv, + allowSiteCrawlers: env.ALLOW_SITE_CRAWLERS, + authorInviteStore: new Keyv({ namespace: 'author-invite', store: createKeyvStore() }), + avatarStore: new Keyv({ namespace: 'avatar-store', store: createKeyvStore() }), + canConnectOrcidProfile: () => true, + canRequestReviews: () => true, + canSeeGatesLogo: true, + canUploadAvatar: () => true, + canUseSearchQueries: () => true, + cloudinaryApi: { cloudName: 'prereview', key: env.CLOUDINARY_API_KEY, secret: env.CLOUDINARY_API_SECRET }, + coarNotifyToken: env.COAR_NOTIFY_TOKEN, + coarNotifyUrl: env.COAR_NOTIFY_URL, + contactEmailAddressStore: new Keyv({ namespace: 'contact-email-address', store: createKeyvStore() }), + environmentLabel: env.ENVIRONMENT_LABEL, + fathomId: env.FATHOM_SITE_ID, + fetch: fetch.defaults({ + cachePath: 'data/cache', + headers: { + 'User-Agent': `PREreview (${env.PUBLIC_URL.href}; mailto:engineering@prereview.org)`, }, - isOpenForRequestsStore: new Keyv({ namespace: 'is-open-for-requests', store: createKeyvStore() }), - isUserBlocked: user => env.BLOCKED_USERS.includes(user), - legacyPrereviewApi: { - app: env.LEGACY_PREREVIEW_API_APP, - key: env.LEGACY_PREREVIEW_API_KEY, - url: env.LEGACY_PREREVIEW_URL, - update: env.LEGACY_PREREVIEW_UPDATE, - }, - languagesStore: new Keyv({ namespace: 'languages', store: createKeyvStore() }), - locationStore: new Keyv({ namespace: 'location', store: createKeyvStore() }), - ...sendMailEnv, - orcidApiUrl: env.ORCID_API_URL, - orcidApiToken: env.ORCID_API_READ_PUBLIC_TOKEN, - orcidOauth: { - authorizeUrl: new URL(`${env.ORCID_URL.origin}/oauth/authorize`), - clientId: env.ORCID_CLIENT_ID, - clientSecret: env.ORCID_CLIENT_SECRET, - revokeUrl: new URL(`${env.ORCID_URL.origin}/oauth/revoke`), - tokenUrl: new URL(`${env.ORCID_URL.origin}/oauth/token`), - }, - orcidTokenStore: new Keyv({ namespace: 'orcid-token', store: createKeyvStore() }), - publicUrl: env.PUBLIC_URL, - redis, - researchInterestsStore: new Keyv({ namespace: 'research-interests', store: createKeyvStore() }), - reviewRequestStore: new Keyv({ namespace: 'review-request', store: createKeyvStore() }), - scietyListToken: env.SCIETY_LIST_TOKEN, - secret: env.SECRET, - sessionCookie: 'session', - sessionStore: new Keyv({ namespace: 'sessions', store: createKeyvStore(), ttl: 1000 * 60 * 60 * 24 * 30 }), - slackOauth: { - authorizeUrl: new URL('https://slack.com/oauth/v2/authorize'), - clientId: env.SLACK_CLIENT_ID, - clientSecret: env.SLACK_CLIENT_SECRET, - tokenUrl: new URL('https://slack.com/api/oauth.v2.access'), - }, - slackApiToken: env.SLACK_API_TOKEN, - slackApiUpdate: env.SLACK_UPDATE, - slackUserIdStore: new Keyv({ namespace: 'slack-user-id', store: createKeyvStore() }), - userOnboardingStore: new Keyv({ namespace: 'user-onboarding', store: createKeyvStore() }), - wasPrereviewRemoved: id => env.REMOVED_PREREVIEWS.includes(id), - zenodoApiKey: env.ZENODO_API_KEY, - zenodoUrl: env.ZENODO_URL, }), -) + formStore: new Keyv({ namespace: 'forms', store: createKeyvStore() }), + careerStageStore: new Keyv({ namespace: 'career-stage', store: createKeyvStore() }), + ghostApi: { + key: env.GHOST_API_KEY, + }, + isOpenForRequestsStore: new Keyv({ namespace: 'is-open-for-requests', store: createKeyvStore() }), + isUserBlocked: user => env.BLOCKED_USERS.includes(user), + legacyPrereviewApi: { + app: env.LEGACY_PREREVIEW_API_APP, + key: env.LEGACY_PREREVIEW_API_KEY, + url: env.LEGACY_PREREVIEW_URL, + update: env.LEGACY_PREREVIEW_UPDATE, + }, + languagesStore: new Keyv({ namespace: 'languages', store: createKeyvStore() }), + locationStore: new Keyv({ namespace: 'location', store: createKeyvStore() }), + ...sendMailEnv, + orcidApiUrl: env.ORCID_API_URL, + orcidApiToken: env.ORCID_API_READ_PUBLIC_TOKEN, + orcidOauth: { + authorizeUrl: new URL(`${env.ORCID_URL.origin}/oauth/authorize`), + clientId: env.ORCID_CLIENT_ID, + clientSecret: env.ORCID_CLIENT_SECRET, + revokeUrl: new URL(`${env.ORCID_URL.origin}/oauth/revoke`), + tokenUrl: new URL(`${env.ORCID_URL.origin}/oauth/token`), + }, + orcidTokenStore: new Keyv({ namespace: 'orcid-token', store: createKeyvStore() }), + publicUrl: env.PUBLIC_URL, + redis, + researchInterestsStore: new Keyv({ namespace: 'research-interests', store: createKeyvStore() }), + reviewRequestStore: new Keyv({ namespace: 'review-request', store: createKeyvStore() }), + scietyListToken: env.SCIETY_LIST_TOKEN, + secret: env.SECRET, + sessionCookie: 'session', + sessionStore: new Keyv({ namespace: 'sessions', store: createKeyvStore(), ttl: 1000 * 60 * 60 * 24 * 30 }), + slackOauth: { + authorizeUrl: new URL('https://slack.com/oauth/v2/authorize'), + clientId: env.SLACK_CLIENT_ID, + clientSecret: env.SLACK_CLIENT_SECRET, + tokenUrl: new URL('https://slack.com/api/oauth.v2.access'), + }, + slackApiToken: env.SLACK_API_TOKEN, + slackApiUpdate: env.SLACK_UPDATE, + slackUserIdStore: new Keyv({ namespace: 'slack-user-id', store: createKeyvStore() }), + userOnboardingStore: new Keyv({ namespace: 'user-onboarding', store: createKeyvStore() }), + wasPrereviewRemoved: id => env.REMOVED_PREREVIEWS.includes(id), + zenodoApiKey: env.ZENODO_API_KEY, + zenodoUrl: env.ZENODO_URL, +}) NodeRuntime.runMain( Layer.launch( Layer.scopedDiscard( Effect.acquireRelease( Effect.sync(() => { - const listeningHttpServer = server.listen(3000) + const listeningHttpServer = expressServer.listen(3000) L.debug('Server listening')(loggerEnv)() return listeningHttpServer }),