Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved serverSetupFn to SDK. #1667

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions waspc/data/Generator/templates/sdk/server/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { type Application } from 'express'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This got moved from server do sdk. That is it really. I also updated one or two paths in server that used it.

import { Server } from 'http'

export type ServerSetupFn = (context: ServerSetupFnContext) => Promise<void>

export type ServerSetupFnContext = {
app: Application,
server: Server,
}

export type { Application } from 'express'
export type { Server } from 'http'
2 changes: 1 addition & 1 deletion waspc/data/Generator/templates/server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import config from 'wasp/server/config'

{=# setupFn.isDefined =}
{=& setupFn.importStatement =}
import { ServerSetupFn, ServerSetupFnContext } from './types'
import { ServerSetupFn, ServerSetupFnContext } from 'wasp/server/types'
{=/ setupFn.isDefined =}

{=# isPgBossJobExecutorUsed =}
Expand Down
13 changes: 0 additions & 13 deletions waspc/data/Generator/templates/server/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
{{={= =}=}}

import { type Application } from 'express'
import { Server } from 'http'

export type ServerSetupFn = (context: ServerSetupFnContext) => Promise<void>

export type ServerSetupFnContext = {
app: Application,
server: Server,
}

export type { Application } from 'express'
export type { Server } from 'http'

{=# isEmailAuthEnabled =}
export type { GetVerificationEmailContentFn, GetPasswordResetEmailContentFn } from '../auth/providers/email/types';
{=/ isEmailAuthEnabled =}
1 change: 1 addition & 0 deletions waspc/examples/todo-typescript/main.wasp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ app TodoTypescript {
system: PostgreSQL
},
server: {
setupFn: import { serverSetup } from "@src/serverSetup.js",
middlewareConfigFn: import { serverMiddlewareFn } from "@src/serverSetup.js"
}
}
Expand Down
8 changes: 8 additions & 0 deletions waspc/examples/todo-typescript/src/serverSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import express from 'express'
import cors from 'cors'
import type { MiddlewareConfigFn } from 'wasp/server/middleware'
import config from 'wasp/server/config'
import type { Application, ServerSetupFn } from 'wasp/server/types'

export const serverMiddlewareFn: MiddlewareConfigFn = (middlewareConfig) => {
// Example of adding an extra domains to CORS.
Expand All @@ -21,3 +22,10 @@ export const fooBarNamespace: MiddlewareConfigFn = (middlewareConfig) => {

return middlewareConfig
}

export const serverSetup: ServerSetupFn = async ({ app }: { app: Application}) => {
app.get('/customRoute', (_req, res) => {
res.send('I am a custom route')
})
console.log("I am a server setup function!");
}
5 changes: 5 additions & 0 deletions waspc/src/Wasp/Generator/SdkGenerator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ genSdkReal spec =
<++> genEntitiesAndServerTypesDirs spec
<++> genApis spec
<++> genMiddleware spec
<++> genExportedTypesDir spec
where
genFileCopy = return . C.mkTmplFd

Expand Down Expand Up @@ -288,6 +289,10 @@ genServerUtils spec = return $ C.mkTmplFdWithData [relfile|server/utils.ts|] tmp
where
tmplData = object ["isAuthEnabled" .= (isAuthEnabled spec :: Bool)]

genExportedTypesDir :: AppSpec -> Generator [FileDraft]
genExportedTypesDir _spec =
return [C.mkTmplFd [relfile|server/types/index.ts|]]

genMiddleware :: AppSpec -> Generator [FileDraft]
genMiddleware _spec =
sequence
Expand Down
4 changes: 1 addition & 3 deletions waspc/src/Wasp/Generator/ServerGenerator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,8 @@ genExportedTypesDir spec =
where
tmplData =
object
[ "isExternalAuthEnabled" .= isExternalAuthEnabled,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was some reminder from the past not used anymore so I removed this line.

"isEmailAuthEnabled" .= isEmailAuthEnabled
[ "isEmailAuthEnabled" .= isEmailAuthEnabled
]
isExternalAuthEnabled = AS.App.Auth.isExternalAuthEnabled <$> maybeAuth
isEmailAuthEnabled = AS.App.Auth.isEmailAuthEnabled <$> maybeAuth
maybeAuth = AS.App.auth $ snd $ getApp spec

Expand Down
Loading