Skip to content

Commit 1136c67

Browse files
authored
Release/1.4.1 (#10)
1 parent f0ae137 commit 1136c67

File tree

7 files changed

+45
-8
lines changed

7 files changed

+45
-8
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## [1.4.1] - 2023-08-18
2+
3+
### Fixed
4+
- fixed `req.url` in Dev Mode, so requests like `/foo?bar=baz` are properly parsed
5+
6+
### Added
7+
- webpack aliases for modules in `client/` and `server/`
8+
- 2 more endpoints to demonstrate the boilerplate's ability to handle various flavours of standard REST endpoints
9+
10+
### Removed
11+
- declaration of the plugin `bodyParser` as it's already bundled within (the opinionated) `somnus`
12+
113
## [1.4.0] - 2022-07-13
214

315
### Changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fullstack-typescript-webapp-starter",
3-
"version": "1.4.0",
3+
"version": "1.4.1",
44
"description": "A db-agnostic, React-based web application starter boilerplate",
55
"scripts": {
66
"build-prod": "scripts/build-prod.sh",

src/server/helper.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,23 @@ export async function submitEntry(req: Request, res: Response): Promise<void> {
7474

7575
}
7676

77+
export async function getEntry(req: Request, res: Response): Promise<void> {
78+
const meta = {
79+
reqUrl: req.url,
80+
reqPath: req.getPath(),
81+
reqQuery: req.query,
82+
reqParams: req.params,
83+
}
84+
const id = req.params?.id;
85+
if (!id) return res.send(400, { message: `missing request query 'id'`, meta });
86+
const col = await getDbCollection(COLLECTION_NAME);
87+
const allEntries = await col.find().toArray();
88+
return res.send({
89+
data: allEntries[id],
90+
meta
91+
});
92+
}
93+
7794
export async function getEntries(req: Request, res: Response): Promise<void> {
7895

7996
const col = await getDbCollection(COLLECTION_NAME);

src/server/main.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
import { Request, Response } from "restify";
2-
import { outputView, submitEntry, getEntries } from "./helper";
2+
import { outputView, submitEntry, getEntry, getEntries } from "./helper";
33
import somnus, { IRouteConfig } from "somnus";
44
import { join } from "path";
55

66
async function main(): Promise<void> {
77

88
process.chdir(__dirname);
99

10-
somnus.server.use(somnus.restify.plugins.bodyParser());
10+
// @NOTE if we use `somnus`, there's no need to declare bodyParser & queryParser
11+
// as they're already bundled into somnus server object
1112

1213
let routeConfig: IRouteConfig = {
1314

1415
"get /": (req: Request, res: Response) => outputView(req, res, "./view-templates/index.html"),
1516

1617
"post /entry": submitEntry,
1718
"get /entries": getEntries,
19+
"get /entry": getEntry,
20+
"get /entry/:id": getEntry,
1821

1922
// in real production, these should be intercepted & handled by a reverse proxy / CDN instead
2023
"get /js/*": somnus.restify.plugins.serveStatic({ directory: "../public" }),

src/server/webpack-dev-middleware-connector.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ async function initWebpackDevMiddleware(app: restify.Server) {
3030
app.pre(
3131
(req, res, next) => {
3232
const thePath = req.getPath();
33-
console.log("somnus: custom whm handling", thePath);
33+
const theBareQuery = req.getQuery();
34+
const theQuery = theBareQuery ? `?${theBareQuery}` : "";
35+
const theUrl = thePath + theQuery;
36+
console.log("somnus wdmwhm: handling", theUrl);
3437
// fix a webpack-hot-middleware - restify incompatibility
35-
req.url = thePath;
38+
req.url = theUrl;
3639
return next();
3740
},
3841
require("webpack-hot-middleware")(compiler, {

src/webpack.shared.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ module.exports = {
2727
// Add '.node' so native modules can be compiled (e.g. `unit-http`).
2828
extensions: [".ts", ".tsx", ".js", ".node"],
2929
alias: {
30-
shared: path.resolve(__dirname, "shared/")
30+
shared: path.resolve(__dirname, "shared/"),
31+
client: path.resolve(__dirname, "client/"),
32+
server: path.resolve(__dirname, "server/"),
3133
}
3234
},
3335

0 commit comments

Comments
 (0)