Skip to content

Commit

Permalink
Avoid awkward pipe limitation
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilkybarkid committed Dec 13, 2024
1 parent 6633ffa commit a6a9394
Showing 1 changed file with 72 additions and 75 deletions.
147 changes: 72 additions & 75 deletions src/LegacyRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,93 +5,90 @@ import { format } from 'fp-ts-routing'
import { StatusCodes } from 'http-status-codes'
import * as Routes from './routes.js'

export const LegacyRouter = HttpRouter.empty
.pipe(
HttpRouter.all(
'/10.1101/:suffix',
pipe(
HttpRouter.schemaParams(Schema.Struct({ suffix: Schema.String })),
Effect.andThen(({ suffix }) =>
movedPermanently(
format(Routes.preprintReviewsMatch.formatter, {
id: {
type: 'biorxiv-medrxiv',
value: `10.1101/${suffix}` as Doi<'1101'>,
},
}),
),
export const LegacyRouter = HttpRouter.fromIterable([
HttpRouter.makeRoute(
'*',
'/10.1101/:suffix',
pipe(
HttpRouter.schemaParams(Schema.Struct({ suffix: Schema.String })),
Effect.andThen(({ suffix }) =>
movedPermanently(
format(Routes.preprintReviewsMatch.formatter, {
id: { type: 'biorxiv-medrxiv', value: `10.1101/${suffix}` as Doi<'1101'> },
}),
),
),
),
HttpRouter.all(
'/10.5281/:suffix',
pipe(
HttpRouter.schemaParams(Schema.Struct({ suffix: Schema.String })),
Effect.andThen(({ suffix }) =>
movedPermanently(
format(Routes.preprintReviewsMatch.formatter, {
id: {
type: 'zenodo-africarxiv',
value: `10.5281/${suffix}` as Doi<'5281'>,
},
}),
),
),
HttpRouter.makeRoute(
'*',
'/10.5281/:suffix',
pipe(
HttpRouter.schemaParams(Schema.Struct({ suffix: Schema.String })),
Effect.andThen(({ suffix }) =>
movedPermanently(
format(Routes.preprintReviewsMatch.formatter, {
id: { type: 'zenodo-africarxiv', value: `10.5281/${suffix}` as Doi<'5281'> },
}),
),
),
),
HttpRouter.all('/blog', movedPermanently('https://content.prereview.org/')),
HttpRouter.all('/coc', movedPermanently(format(Routes.codeOfConductMatch.formatter, {}))),
HttpRouter.all('/communities', movedPermanently(format(Routes.clubsMatch.formatter, {}))),
HttpRouter.all('/docs/about', movedPermanently(Routes.AboutUs)),
HttpRouter.all('/docs/codeofconduct', movedPermanently(format(Routes.codeOfConductMatch.formatter, {}))),
HttpRouter.all('/docs/code_of_conduct', movedPermanently(format(Routes.codeOfConductMatch.formatter, {}))),
HttpRouter.all('/docs/resources', movedPermanently(format(Routes.resourcesMatch.formatter, {}))),
HttpRouter.all('/edi-statement', movedPermanently(format(Routes.ediaStatementMatch.formatter, {}))),
HttpRouter.all('/edia', movedPermanently(format(Routes.ediaStatementMatch.formatter, {}))),
HttpRouter.all('/find-a-preprint', movedPermanently(format(Routes.reviewAPreprintMatch.formatter, {}))),
HttpRouter.all(
'/inst/:instId',
pipe(
HttpRouter.schemaParams(Schema.Struct({ instId: Schema.String })),
Effect.andThen(({ instId }) => movedPermanently(`https://www.authorea.com/inst/${instId}`)),
),
),
HttpRouter.makeRoute('*', '/blog', movedPermanently('https://content.prereview.org/')),
HttpRouter.makeRoute('*', '/coc', movedPermanently(format(Routes.codeOfConductMatch.formatter, {}))),
HttpRouter.makeRoute('*', '/communities', movedPermanently(format(Routes.clubsMatch.formatter, {}))),
HttpRouter.makeRoute('*', '/docs/about', movedPermanently(Routes.AboutUs)),
HttpRouter.makeRoute('*', '/docs/codeofconduct', movedPermanently(format(Routes.codeOfConductMatch.formatter, {}))),
HttpRouter.makeRoute('*', '/docs/code_of_conduct', movedPermanently(format(Routes.codeOfConductMatch.formatter, {}))),
HttpRouter.makeRoute('*', '/docs/resources', movedPermanently(format(Routes.resourcesMatch.formatter, {}))),
HttpRouter.makeRoute('*', '/edi-statement', movedPermanently(format(Routes.ediaStatementMatch.formatter, {}))),
HttpRouter.makeRoute('*', '/edia', movedPermanently(format(Routes.ediaStatementMatch.formatter, {}))),
HttpRouter.makeRoute('*', '/find-a-preprint', movedPermanently(format(Routes.reviewAPreprintMatch.formatter, {}))),
HttpRouter.makeRoute(
'*',
'/inst/:instId',
pipe(
HttpRouter.schemaParams(Schema.Struct({ instId: Schema.String })),
Effect.andThen(({ instId }) => movedPermanently(`https://www.authorea.com/inst/${instId}`)),
),
HttpRouter.all('/login', movedPermanently(format(Routes.logInMatch.formatter, {}))),
HttpRouter.all('/logout', movedPermanently(format(Routes.logOutMatch.formatter, {}))),
HttpRouter.all('/preprint-journal-clubs', movedPermanently(format(Routes.liveReviewsMatch.formatter, {}))),
HttpRouter.all('/prereview.org', movedPermanently(format(Routes.homeMatch.formatter, {}))),
HttpRouter.all('/reviews/new', movedPermanently(format(Routes.reviewAPreprintMatch.formatter, {}))),
HttpRouter.all('/signup', movedPermanently(format(Routes.logInMatch.formatter, {}))),
HttpRouter.all(
'/users/:userId/articles/:articleId',
pipe(
HttpRouter.schemaParams(Schema.Struct({ articleId: Schema.String, userId: Schema.String })),
Effect.andThen(({ articleId, userId }) =>
movedPermanently(encodeURI(`https://www.authorea.com/users/${userId}/articles/${articleId}`)),
),
),
HttpRouter.makeRoute('*', '/login', movedPermanently(format(Routes.logInMatch.formatter, {}))),
HttpRouter.makeRoute('*', '/logout', movedPermanently(format(Routes.logOutMatch.formatter, {}))),
HttpRouter.makeRoute('*', '/preprint-journal-clubs', movedPermanently(format(Routes.liveReviewsMatch.formatter, {}))),
HttpRouter.makeRoute('*', '/prereview.org', movedPermanently(format(Routes.homeMatch.formatter, {}))),
HttpRouter.makeRoute('*', '/reviews/new', movedPermanently(format(Routes.reviewAPreprintMatch.formatter, {}))),
HttpRouter.makeRoute('*', '/signup', movedPermanently(format(Routes.logInMatch.formatter, {}))),
HttpRouter.makeRoute(
'*',
'/users/:userId/articles/:articleId',
pipe(
HttpRouter.schemaParams(Schema.Struct({ articleId: Schema.String, userId: Schema.String })),
Effect.andThen(({ articleId, userId }) =>
movedPermanently(encodeURI(`https://www.authorea.com/users/${userId}/articles/${articleId}`)),
),
),
)
.pipe(
HttpRouter.all(
'/users/:userId',
pipe(
HttpRouter.schemaParams(Schema.Struct({ userId: Schema.String })),
Effect.andThen(({ userId }) => movedPermanently(`https://www.authorea.com/users/${userId}`)),
),
),
HttpRouter.makeRoute(
'*',
'/users/:userId',
pipe(
HttpRouter.schemaParams(Schema.Struct({ userId: Schema.String })),
Effect.andThen(({ userId }) => movedPermanently(`https://www.authorea.com/users/${userId}`)),
),
HttpRouter.all(
'/users/:userId/articles/:articleId/_show_article',
pipe(
HttpRouter.schemaParams(Schema.Struct({ articleId: Schema.String, userId: Schema.String })),
Effect.andThen(({ articleId, userId }) =>
movedPermanently(encodeURI(`https://www.authorea.com/users/${userId}/articles/${articleId}`)),
),
),
HttpRouter.makeRoute(
'*',
'/users/:userId/articles/:articleId/_show_article',
pipe(
HttpRouter.schemaParams(Schema.Struct({ articleId: Schema.String, userId: Schema.String })),
Effect.andThen(({ articleId, userId }) =>
movedPermanently(encodeURI(`https://www.authorea.com/users/${userId}/articles/${articleId}`)),
),
),
HttpRouter.all('/)', movedPermanently(format(Routes.homeMatch.formatter, {}))),
HttpRouter.all('/),', movedPermanently(format(Routes.homeMatch.formatter, {}))),
)
),
HttpRouter.makeRoute('*', '/)', movedPermanently(format(Routes.homeMatch.formatter, {}))),
HttpRouter.makeRoute('*', '/),', movedPermanently(format(Routes.homeMatch.formatter, {}))),
])

function movedPermanently(location: string) {
return HttpServerResponse.empty({
Expand Down

0 comments on commit a6a9394

Please sign in to comment.