Skip to content

Commit

Permalink
chore: upgrade to express v5
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Nov 17, 2024
1 parent e2d4970 commit 20610af
Show file tree
Hide file tree
Showing 20 changed files with 338 additions and 140 deletions.
422 changes: 310 additions & 112 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"@indiekit-test/token": "*",
"@micham/sftp-mock-server": "^0.0.6",
"@types/cookie-session": "^2.0.44",
"@types/express": "^4.17.17",
"@types/express": "^5.0.0",
"@types/express-fileupload": "^1.4.1",
"@types/lodash": "^4.14.195",
"aws-sdk-client-mock": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/endpoint-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@indiekit/error": "^1.0.0-beta.15",
"@indiekit/util": "^1.0.0-beta.19",
"bcrypt": "^5.1.0",
"express": "^4.17.1",
"express": "^5.0.0",
"express-validator": "^7.0.0",
"jsonwebtoken": "^9.0.0",
"microformats-parser": "^2.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/endpoint-files/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class FilesEndpoint {
router.get("/upload", fileData.upload, formController.get);
router.post("/upload", fileData.upload, validate, formController.post);

router.use("/:uid/:action?", fileData.read);
router.use("/:uid{/:action}", fileData.read);
router.get("/:uid", fileController);

router.get("/:uid/delete", deleteController.get);
Expand Down
2 changes: 1 addition & 1 deletion packages/endpoint-files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
"dependencies": {
"@indiekit/error": "^1.0.0-beta.15",
"express": "^4.17.1",
"express": "^5.0.0",
"express-validator": "^7.0.0"
},
"publishConfig": {
Expand Down
2 changes: 1 addition & 1 deletion packages/endpoint-image/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"directory": "packages/endpoint-image"
},
"dependencies": {
"express": "^4.17.1",
"express": "^5.0.0",
"ipx": "^3.0.0"
},
"publishConfig": {
Expand Down
2 changes: 1 addition & 1 deletion packages/endpoint-json-feed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"directory": "packages/endpoint-json-feed"
},
"dependencies": {
"express": "^4.17.1",
"express": "^5.0.0",
"mime-types": "^2.1.35"
},
"publishConfig": {
Expand Down
4 changes: 2 additions & 2 deletions packages/endpoint-media/lib/controllers/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { checkScope } from "../scope.js";
export const actionController = (imageProcessing) =>
async function (request, response, next) {
const { app, body, files, query, session } = request;
const action = query.action || body.action || "media";
const url = query.url || body.url;
const action = query.action || body?.action || "media";
const url = query.url || body?.url;
const { application, publication } = app.locals;

try {
Expand Down
2 changes: 1 addition & 1 deletion packages/endpoint-media/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@indiekit/util": "^1.0.0-beta.19",
"debug": "^4.3.2",
"deepmerge": "^4.3.1",
"express": "^4.17.1",
"express": "^5.0.0",
"file-type": "^19.0.0",
"newbase60": "^1.3.1",
"sharp": "^0.33.2"
Expand Down
4 changes: 2 additions & 2 deletions packages/endpoint-micropub/lib/controllers/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { uploadMedia } from "../media.js";
*/
export const actionController = async (request, response, next) => {
const { app, body, files, query, session } = request;
const action = query.action || body.action || "create";
const url = query.url || body.url;
const action = query.action || body?.action || "create";
const url = query.url || body?.url;
const { application, publication } = app.locals;

try {
Expand Down
2 changes: 1 addition & 1 deletion packages/endpoint-micropub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@indiekit/util": "^1.0.0-beta.19",
"@paulrobertlloyd/mf2tojf2": "^2.1.0",
"debug": "^4.3.2",
"express": "^4.17.1",
"express": "^5.0.0",
"lodash": "^4.17.21",
"markdown-it": "^14.0.0",
"newbase60": "^1.3.1",
Expand Down
6 changes: 3 additions & 3 deletions packages/endpoint-posts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ export default class PostsEndpoint {
router.get("/create", postData.create, formController.get);
router.post("/create", postData.create, validate.form, formController.post);

router.use("/:uid/:action?", postData.read);
router.use("/:uid{/:action}", postData.read);
router.get("/:uid", postController);

router.get("/:uid/update", formController.get);
router.post("/:uid/update", validate.form, formController.post);

router.get("/:uid/:action(delete|undelete)", deleteController.get);
router.post("/:uid/:action(delete|undelete)", deleteController.post);
router.get(["/:uid/delete", "/:uid/undelete"], deleteController.get);
router.post(["/:uid/delete", "/:uid/undelete"], deleteController.post);

return router;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/endpoint-posts/lib/middleware/post-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ export const postData = {

// Create new post object with default values
const postType = request.query.type || "note";
const properties = request.body;
const properties = request?.body || {};

// Get post type config
const { name, fields, h } = publication.postTypes[postType];

// Only select ‘checked’ syndication targets on first view
const checkTargets = Object.entries(request.body).length === 0;
const checkTargets = Object.entries(properties).length === 0;

response.locals = {
accessToken: access_token,
Expand Down
2 changes: 1 addition & 1 deletion packages/endpoint-posts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@indiekit/frontend": "^1.0.0-beta.19",
"@indiekit/util": "^1.0.0-beta.19",
"@paulrobertlloyd/mf2tojf2": "^2.1.0",
"express": "^4.17.1",
"express": "^5.0.0",
"express-validator": "^7.0.0",
"formatcoords": "^1.1.3"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/endpoint-share/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export default class ShareEndpoint {
}

get routes() {
router.get("/:path?", shareController.get);
router.post("/:path?", validate, shareController.post);
router.get("/{:path}", shareController.get);
router.post("/{:path}", validate, shareController.post);

return router;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/endpoint-share/lib/controllers/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export const shareController = {
*/
async post(request, response) {
const { application } = request.app.locals;
const data = request.body;
data["bookmark-of"] = data.url || request.body["bookmark-of"];
const data = request.body || {};
data["bookmark-of"] = data.url || data["bookmark-of"];

const errors = validationResult(request);
if (!errors.isEmpty()) {
Expand All @@ -43,7 +43,7 @@ export const shareController = {
accept: "application/json",
"content-type": "application/x-www-form-urlencoded",
},
body: new URLSearchParams(request.body).toString(),
body: new URLSearchParams(data).toString(),
});

if (!micropubResponse.ok) {
Expand Down
2 changes: 1 addition & 1 deletion packages/endpoint-share/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"dependencies": {
"@indiekit/error": "^1.0.0-beta.15",
"express": "^4.17.1",
"express": "^5.0.0",
"express-validator": "^7.0.0"
},
"publishConfig": {
Expand Down
4 changes: 2 additions & 2 deletions packages/endpoint-syndicate/lib/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { IndiekitError } from "@indiekit/error";
import jwt from "jsonwebtoken";

export const findBearerToken = (request) => {
if (request.headers?.["x-webhook-signature"]) {
if (request.headers?.["x-webhook-signature"] && request?.body?.url) {
const signature = request.headers["x-webhook-signature"];
const verifiedToken = verifyToken(signature);
const bearerToken = signToken(verifiedToken, request.body.url);
return bearerToken;
}

if (request.body?.access_token) {
if (request?.body?.access_token) {
const bearerToken = request.body.access_token;
delete request.body.access_token;
return bearerToken;
Expand Down
2 changes: 1 addition & 1 deletion packages/endpoint-syndicate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
"dependencies": {
"@indiekit/error": "^1.0.0-beta.15",
"express": "^4.17.1",
"express": "^5.0.0",
"jsonwebtoken": "^9.0.0"
},
"publishConfig": {
Expand Down
2 changes: 1 addition & 1 deletion packages/indiekit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"cosmiconfig": "^9.0.0",
"debug": "^4.3.2",
"deepmerge": "^4.2.2",
"express": "^4.17.1",
"express": "^5.0.0",
"express-fileupload": "^1.4.0",
"express-rate-limit": "^7.0.0",
"i18n": "^0.15.0",
Expand Down

0 comments on commit 20610af

Please sign in to comment.