Skip to content

Commit

Permalink
refactor: refactor the app creator: add support for JSON request body
Browse files Browse the repository at this point in the history
  • Loading branch information
simplymichael committed Jun 21, 2024
1 parent 3ef4b2d commit ca5c72f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
10 changes: 3 additions & 7 deletions src/framework/application/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const createError = require("http-errors");
const bootstrap = require("../../bootstrap");
const container = require("../../component/container");
const Connections = require("../../connections");
const { StatusCodes, StatusTexts } = require("../../component/http");
const Router = require("../../component/router");
const view = require("../../component/view");
const requestLogger = require("../../component/middleware/request-logger");
const session = require("../../component/middleware/session");

/**
Expand Down Expand Up @@ -71,8 +71,6 @@ module.exports = function createApp(options) {
bootstrap(config, providers);

const app = express();
const STATUS_CODES = Object.assign(Object.create(null), StatusCodes);
const STATUS_TEXTS = Object.assign(Object.create(null), StatusTexts);

let sessionStore;

Expand Down Expand Up @@ -109,6 +107,8 @@ module.exports = function createApp(options) {
app.set("views", config.get("app.viewsDir"));
app.set("view engine", config.get("app.viewTemplatesEngine", "pug"));

app.use(requestLogger(app));
app.use(express.json());
app.use(view.init);
app.use(express.static(path.join(config.get("app.srcDir"), "public")));
app.use(express.urlencoded({ extended: false }));
Expand All @@ -124,8 +124,6 @@ module.exports = function createApp(options) {
router,
download: view.downloadFile,
view: view.viewFile,
STATUS_CODES,
STATUS_TEXTS,
}));
}

Expand All @@ -134,8 +132,6 @@ module.exports = function createApp(options) {
router,
download: view.downloadFile,
view: view.viewFile,
STATUS_CODES,
STATUS_TEXTS,
}));
}

Expand Down
8 changes: 6 additions & 2 deletions src/framework/component/http/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"use strict";

const StatusCodes = require("./status-codes");
const StatusTexts = require("./status-texts").statusTexts;


module.exports = {
StatusCodes: require("./status-codes"),
StatusTexts: require("./status-texts").statusTexts,
STATUS_CODES: Object.assign(Object.create(null), StatusCodes),
STATUS_TEXTS: Object.assign(Object.create(null), StatusTexts),
//CacheControlDirectives: require("./cache-control-directives").HTTP_RESPONSE_CACHE_CONTROL_DIRECTIVES,
};
3 changes: 2 additions & 1 deletion src/routes/api.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const { STATUS_CODES, STATUS_TEXTS } = require("../framework/component/http");
const createCache = require("../framework/component/middleware/cache");

const cache = createCache({ duration: 0 });


module.exports = function apiRouter({ router, STATUS_CODES, STATUS_TEXTS }) {
module.exports = function apiRouter({ router }) {
/*
* Apply the cache middleware to every router in this group.
*/
Expand Down

0 comments on commit ca5c72f

Please sign in to comment.