-
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.
- Loading branch information
Showing
23 changed files
with
4,311 additions
and
103 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "express-typed--prisma-demo", | ||
"version": "1.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "tsx watch src/app.ts" | ||
}, | ||
"dependencies": { | ||
"@types/express": "^4.17.21", | ||
"@types/morgan": "^1.9.9", | ||
"@types/node": "^20.12.7", | ||
"axios": "^1.6.8", | ||
"express": "^4.19.2", | ||
"express-typed": "workspace:*", | ||
"morgan": "^1.10.0" | ||
}, | ||
"devDependencies": { | ||
"tsx": "^4.7.2" | ||
} | ||
} |
File renamed without changes.
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,18 @@ | ||
import express from "express"; | ||
import logger from "morgan"; | ||
import typedRouter from "./routes/index.routes"; | ||
|
||
// Create Express server | ||
export const app = express(); | ||
|
||
app.use(logger("dev")); | ||
|
||
// Parse incoming requests data | ||
app.use(express.urlencoded({ extended: true })); | ||
app.use(express.json()); | ||
|
||
app.use("/", typedRouter.router); | ||
|
||
const server = app.listen(4000, () => { | ||
console.log(`Listening on port ${4000}`); | ||
}); |
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,25 @@ | ||
import { GetRouteResponseInfo, TypedRouter, ParseRoutes, GetRouteResponseInfoHelper, HandlerMethods, KeysWithMethod, GetRouterMethods, GetRoutesWithMethod } from "express-typed"; | ||
|
||
const typedRouter = new TypedRouter({ | ||
// example usage | ||
"/": { | ||
get: (req, res) => { | ||
return res.send("Hello world").status(200); | ||
}, | ||
}, | ||
}); | ||
|
||
export default typedRouter; | ||
|
||
export type AppRoutes = ParseRoutes<typeof typedRouter>; | ||
|
||
export type RouteResolver< | ||
Path extends keyof AppRoutes, | ||
Method extends keyof AppRoutes[Path], | ||
Info extends keyof GetRouteResponseInfoHelper<AppRoutes, Path, Method> | "body" = "body" | ||
> = GetRouteResponseInfo<AppRoutes, Path, Method, Info>; | ||
|
||
|
||
export type RoutesWithMethod<Method extends GetRouterMethods<AppRoutes>> = GetRoutesWithMethod<AppRoutes, Method>; | ||
|
||
|
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,11 @@ | ||
import { TypedRouter } from "express-typed"; | ||
|
||
const typedRouter = new TypedRouter({ | ||
"/": { | ||
get: (req, res) => { | ||
return res.send("even-more-nested").status(200); | ||
}, | ||
}, | ||
}); | ||
|
||
export default typedRouter; |
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
File renamed without changes.
Oops, something went wrong.