generated from K-FOSS/TS-Core-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Working, now just need to patch React
- Loading branch information
Showing
13 changed files
with
2,151 additions
and
103 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// src/ | ||
import { getGQLContext } from './Context'; | ||
|
||
type ApolloServer = import('apollo-server-fastify').ApolloServer; | ||
type ApolloServerTestClient = import('apollo-server-testing').ApolloServerTestClient; | ||
|
||
let gqlServer: ApolloServer; | ||
|
||
/** | ||
* Create Apollo GraphQL Server | ||
* | ||
* @returns Promise that resolves to a ApolloServer Instance | ||
*/ | ||
export async function createApolloServer(): Promise<ApolloServer> { | ||
if (!gqlServer) { | ||
const [ | ||
{ ApolloServer }, | ||
{ getResolvers, buildGQLSchema }, | ||
] = await Promise.all([ | ||
import('apollo-server-fastify'), | ||
import('./Resolvers'), | ||
]); | ||
|
||
const resolvers = await getResolvers(); | ||
|
||
gqlServer = new ApolloServer({ | ||
schema: await buildGQLSchema(resolvers), | ||
context: getGQLContext, | ||
introspection: true, | ||
playground: { | ||
settings: { | ||
'editor.theme': 'light', | ||
'general.betaUpdates': true, | ||
}, | ||
workspaceName: 'TS-ESWeb', | ||
}, | ||
}); | ||
} | ||
|
||
return gqlServer; | ||
} | ||
|
||
/** | ||
* Create a Apollo Server Testing instance | ||
*/ | ||
export async function createApolloTestClient(): Promise<ApolloServerTestClient> { | ||
const { createTestClient } = await import('apollo-server-testing'); | ||
|
||
const gqlServer = await createApolloServer(); | ||
|
||
return createTestClient(gqlServer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// src/Library/Context.ts | ||
|
||
interface Context { | ||
randomValue: 42; | ||
} | ||
|
||
/** | ||
* Get the GraphQL Context | ||
*/ | ||
export async function getGQLContext(): Promise<Context> { | ||
/** | ||
* The answer to life and everything in the universe | ||
*/ | ||
const answerToEverything = 42; | ||
|
||
return { | ||
randomValue: answerToEverything, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,27 @@ | ||
/* eslint-disable @typescript-eslint/ban-types */ | ||
// src/Modules/SSR/SSRRoute.ts | ||
import { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify'; | ||
import { HMRLoader } from '../../Utils/hmrLoader'; | ||
import { Route } from '../../Library/Fastify'; | ||
import { ssrServer } from '../Server/createSSRServer'; | ||
|
||
/** | ||
* Route to serve the rendered React SSR Routes | ||
*/ | ||
export default class SSRRoute implements Route { | ||
public options: Route['options'] = { | ||
method: 'GET', | ||
url: '/*', | ||
url: '/Test', | ||
}; | ||
|
||
public async handler( | ||
this: FastifyInstance, | ||
request: FastifyRequest, | ||
reply: FastifyReply, | ||
): Promise<Function> { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
const { renderWeb } = await HMRLoader( | ||
'../../../Web/Server', | ||
import.meta.url, | ||
); | ||
): Promise<string> { | ||
reply.type('text/html'); | ||
|
||
await reply.type('text/html'); | ||
const appHTML = ssrServer.renderApp(request.url); | ||
|
||
return renderWeb(request.req.url!); | ||
return appHTML; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,21 @@ | ||
// src/Modules/Server/createSSRServer.ts | ||
import { ReactFunction } from '../../Utils/React'; | ||
import { timeout } from '../../Utils/timeout'; | ||
import { SSRServer } from './SSRServer'; | ||
import { ClientOptions, SSRServer } from './SSRServer'; | ||
|
||
interface SSRServerOptions { | ||
/** | ||
* App | ||
*/ | ||
appComponent: ReactFunction; | ||
|
||
/** | ||
* Root Directory for Web/Client | ||
* | ||
* @example | ||
* ```ts | ||
* webRoot: path.resolve('./Web') | ||
* ``` | ||
*/ | ||
webRoot: string; | ||
|
||
/** | ||
* Entrypoint Path relative to @see webRoot | ||
*/ | ||
entrypoint: string; | ||
options: ClientOptions; | ||
} | ||
|
||
export let ssrServer: SSRServer; | ||
|
||
export async function createSSRServer({ | ||
...opts | ||
options, | ||
}: SSRServerOptions): Promise<SSRServer> { | ||
await timeout(100); | ||
await timeout(50); | ||
|
||
console.log(`Creating SSR Server with specified configuration`); | ||
|
||
return new SSRServer(opts); | ||
ssrServer = new SSRServer(options); | ||
|
||
return ssrServer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.