-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved middleware configuration to SDK + fixed sdk/server/config.
- Loading branch information
Showing
9 changed files
with
129 additions
and
10 deletions.
There are no files selected for viewing
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
6 changes: 6 additions & 0 deletions
6
waspc/data/Generator/templates/sdk/server/middleware/globalMiddleware.ts
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,6 @@ | ||
import { type RequestHandler } from 'express' | ||
|
||
export type MiddlewareConfig = Map<string, RequestHandler> | ||
|
||
export type MiddlewareConfigFn = (middlewareConfig: MiddlewareConfig) => MiddlewareConfig | ||
|
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 @@ | ||
export * from './globalMiddleware.js' |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
{ | ||
"name": "prototype", | ||
"dependencies": { | ||
"wasp": "file:.wasp/out/sdk/wasp", | ||
"react": "^18.2.0" | ||
"cors": "^2.8.5", | ||
"react": "^18.2.0", | ||
"wasp": "file:.wasp/out/sdk/wasp" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^5.1.0", | ||
"vite": "^4.3.9", | ||
"@types/cors": "^2.8.5", | ||
"@types/express": "^4.17.13", | ||
"@types/react": "^18.0.37", | ||
"prisma": "4.16.2" | ||
"prisma": "4.16.2", | ||
"typescript": "^5.1.0", | ||
"vite": "^4.3.9" | ||
} | ||
} |
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,23 @@ | ||
import express from 'express' | ||
import cors from 'cors' | ||
import type { MiddlewareConfigFn } from 'wasp/server/middleware' | ||
import config from 'wasp/server/config' | ||
|
||
export const serverMiddlewareFn: MiddlewareConfigFn = (middlewareConfig) => { | ||
// Example of adding an extra domains to CORS. | ||
middlewareConfig.set('cors', cors({ | ||
origin: [config.frontendUrl, 'https://example1.com', 'https://example2.com'] | ||
})) | ||
return middlewareConfig | ||
} | ||
|
||
export const fooBarNamespace: MiddlewareConfigFn = (middlewareConfig) => { | ||
const customMiddleware: express.RequestHandler = (_req, _res, next) => { | ||
console.log('fooBarNamespaceMiddlewareFn: custom middleware') | ||
next() | ||
} | ||
|
||
middlewareConfig.set('custom.middleware', customMiddleware) | ||
|
||
return middlewareConfig | ||
} |
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