Skip to content

Commit bac7bd4

Browse files
authored
Migrate server code to server/index.ts and simplify processes (#1066)
* Migrate server-side code to `server/index.ts`, remove `server-build` structure, and streamline build and dev processes * Update Node.js engine requirement to `^22.18.0` in package configuration and documentation * Fix types in test * Fix types in test
1 parent bc2b020 commit bac7bd4

File tree

16 files changed

+120
-172
lines changed

16 files changed

+120
-172
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ node_modules
22
.DS_store
33

44
/build
5-
/server-build
65
.env
76
.cache
87

.prettierignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ node_modules
22

33
/build
44
/public/build
5-
/server-build
65
.env
76

87
/test-results/

app/routes/_auth/auth.$provider/callback.test.ts

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { invariant } from '@epic-web/invariant'
22
import { faker } from '@faker-js/faker'
33
import { SetCookie } from '@mjackson/headers'
44
import { http } from 'msw'
5+
import { type AppLoadContext } from 'react-router'
56
import { afterEach, expect, test } from 'vitest'
67
import { twoFAVerificationType } from '#app/routes/settings/profile/two-factor/_layout.tsx'
78
import { getSessionExpirationDate, sessionKey } from '#app/utils/auth.server.ts'
@@ -25,9 +26,11 @@ afterEach(async () => {
2526

2627
test('a new user goes to onboarding', async () => {
2728
const request = await setupRequest()
28-
const response = await loader({ request, params: PARAMS, context: {} }).catch(
29-
(e) => e,
30-
)
29+
const response = await loader({
30+
request,
31+
params: PARAMS,
32+
context: {} as AppLoadContext,
33+
}).catch((e) => e)
3134
expect(response).toHaveRedirect('/onboarding/github')
3235
})
3336

@@ -39,9 +42,11 @@ test('when auth fails, send the user to login with a toast', async () => {
3942
}),
4043
)
4144
const request = await setupRequest()
42-
const response = await loader({ request, params: PARAMS, context: {} }).catch(
43-
(e) => e,
44-
)
45+
const response = await loader({
46+
request,
47+
params: PARAMS,
48+
context: {} as AppLoadContext,
49+
}).catch((e) => e)
4550
invariant(response instanceof Response, 'response should be a Response')
4651
expect(response).toHaveRedirect('/login')
4752
await expect(response).toSendToast(
@@ -60,7 +65,11 @@ test('when a user is logged in, it creates the connection', async () => {
6065
sessionId: session.id,
6166
code: githubUser.code,
6267
})
63-
const response = await loader({ request, params: PARAMS, context: {} })
68+
const response = await loader({
69+
request,
70+
params: PARAMS,
71+
context: {} as AppLoadContext,
72+
})
6473
expect(response).toHaveRedirect('/settings/profile/connections')
6574
await expect(response).toSendToast(
6675
expect.objectContaining({
@@ -96,7 +105,11 @@ test(`when a user is logged in and has already connected, it doesn't do anything
96105
sessionId: session.id,
97106
code: githubUser.code,
98107
})
99-
const response = await loader({ request, params: PARAMS, context: {} })
108+
const response = await loader({
109+
request,
110+
params: PARAMS,
111+
context: {} as AppLoadContext,
112+
})
100113
expect(response).toHaveRedirect('/settings/profile/connections')
101114
await expect(response).toSendToast(
102115
expect.objectContaining({
@@ -111,7 +124,11 @@ test('when a user exists with the same email, create connection and make session
111124
const email = githubUser.primaryEmail.toLowerCase()
112125
const { userId } = await setupUser({ ...createUser(), email })
113126
const request = await setupRequest({ code: githubUser.code })
114-
const response = await loader({ request, params: PARAMS, context: {} })
127+
const response = await loader({
128+
request,
129+
params: PARAMS,
130+
context: {} as AppLoadContext,
131+
})
115132

116133
expect(response).toHaveRedirect('/')
117134

@@ -155,7 +172,11 @@ test('gives an error if the account is already connected to another user', async
155172
sessionId: session.id,
156173
code: githubUser.code,
157174
})
158-
const response = await loader({ request, params: PARAMS, context: {} })
175+
const response = await loader({
176+
request,
177+
params: PARAMS,
178+
context: {} as AppLoadContext,
179+
})
159180
expect(response).toHaveRedirect('/settings/profile/connections')
160181
await expect(response).toSendToast(
161182
expect.objectContaining({
@@ -178,7 +199,11 @@ test('if a user is not logged in, but the connection exists, make a session', as
178199
},
179200
})
180201
const request = await setupRequest({ code: githubUser.code })
181-
const response = await loader({ request, params: PARAMS, context: {} })
202+
const response = await loader({
203+
request,
204+
params: PARAMS,
205+
context: {} as AppLoadContext,
206+
})
182207
expect(response).toHaveRedirect('/')
183208
await expect(response).toHaveSessionForUser(userId)
184209
})
@@ -202,7 +227,11 @@ test('if a user is not logged in, but the connection exists and they have enable
202227
},
203228
})
204229
const request = await setupRequest({ code: githubUser.code })
205-
const response = await loader({ request, params: PARAMS, context: {} })
230+
const response = await loader({
231+
request,
232+
params: PARAMS,
233+
context: {} as AppLoadContext,
234+
})
206235
const searchParams = new URLSearchParams({
207236
type: twoFAVerificationType,
208237
target: userId,

app/routes/_seo/sitemap[.]xml.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import { generateSitemap } from '@nasa-gcn/remix-seo'
2-
import { type ServerBuild } from 'react-router'
32
import { getDomainUrl } from '#app/utils/misc.tsx'
43
import { type Route } from './+types/sitemap[.]xml.ts'
54

65
export async function loader({ request, context }: Route.LoaderArgs) {
7-
const serverBuild = (await context.serverBuild) as { build: ServerBuild }
8-
96
// TODO: This is typeerror is coming up since of the remix-run/server-runtime package. We might need to remove/update that one.
107
// @ts-expect-error
11-
return generateSitemap(request, serverBuild.build.routes, {
8+
return generateSitemap(request, context.serverBuild.routes, {
129
siteUrl: getDomainUrl(request),
1310
headers: {
1411
'Cache-Control': `public, max-age=${60 * 5}`,

docs/authentication.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ is a precondition for a "Mock GitHub server" to be installed (with the help of
4444
calls to `https://github.com/login/oauth/access_token` are being intercepted.
4545
But once deployed to an environment where `process.env.MOCKS` is not set to
4646
`'true'` (see how this is done when launching the
47-
[dev server](../server/dev-server.js) and checked in the
48-
[entrypoint](../index.js)), or even when developing _locally_ but not setting
47+
[server](../server/index.ts) and checked in the
48+
[entrypoint](../index.ts)), or even when developing _locally_ but not setting
4949
`GITHUB_CLIENT_ID` to `MOCK_...`, the requests will actually reach the GitHub
5050
auth server. This is where you will want to have a GitHub OAuth application
5151
properly set up, otherwise the logging in with GitHub will fail and a

docs/managing-updates.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@ If you wish to change the Node.js version, you can do so by updating the
1212
```json
1313
{
1414
"engines": {
15-
"node": "20.3.1"
15+
"node": "^22.18.0"
1616
}
1717
}
1818
```
1919

20-
Make certain you do not use a version range here because this is used in the
21-
`./other/build-server.ts` to compile the express server code.
22-
2320
You will also want to update the `Dockerfile` to use the same version of Node.js
2421
as the `package.json` file.
2522

index.js renamed to index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,4 @@ if (process.env.MOCKS === 'true') {
2020
await import('./tests/mocks/index.ts')
2121
}
2222

23-
if (process.env.NODE_ENV === 'production') {
24-
await import('./server-build/index.js')
25-
} else {
26-
await import('./server/index.ts')
27-
}
23+
await import('./server/index.ts')

other/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ RUN INTERNAL_COMMAND_TOKEN=$(openssl rand -hex 32) && \
8181
COPY --from=production-deps /myapp/node_modules /myapp/node_modules
8282
COPY --from=build /myapp/node_modules/.prisma /myapp/node_modules/.prisma
8383

84-
COPY --from=build /myapp/server-build /myapp/server-build
8584
COPY --from=build /myapp/build /myapp/build
8685
COPY --from=build /myapp/package.json /myapp/package.json
8786
COPY --from=build /myapp/prisma /myapp/prisma

other/build-server.ts

Lines changed: 0 additions & 50 deletions
This file was deleted.

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)