@apolitical/server 2.3.1 → 2.3.2-rc.static.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [2.3.2] - 2022-02-21
9
+ ### Changed
10
+ - loading static files middleware after the app has been loaded
11
+
8
12
  ## [2.3.1] - 2022-02-15
9
13
  ### Changed
10
14
  - Body parser types
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apolitical/server",
3
- "version": "2.3.1",
3
+ "version": "2.3.2-rc.static.1",
4
4
  "description": "Node.js module to encapsulate Apolitical's express server setup",
5
5
  "author": "Apolitical Group Limited <engineering@apolitical.co>",
6
6
  "license": "MIT",
package/src/container.js CHANGED
@@ -35,6 +35,7 @@ const jwtPassportHelper = require('./helpers/jwt/passport.helper');
35
35
  const documentationLoader = require('./loaders/documentation.loader');
36
36
  const loggerLoader = require('./loaders/logger.loader');
37
37
  const middlewaresLoader = require('./loaders/middlewares.loader');
38
+ const staticLoader = require('./loaders/static.loader');
38
39
  const probesLoader = require('./loaders/probes.loader');
39
40
  const fallbackLoader = require('./loaders/fallback.loader');
40
41
  // Middleware
@@ -84,6 +85,7 @@ container.register({
84
85
  documentationLoader: asFunction(documentationLoader).singleton(),
85
86
  loggerLoader: asFunction(loggerLoader).singleton(),
86
87
  middlewaresLoader: asFunction(middlewaresLoader).singleton(),
88
+ staticLoader: asFunction(staticLoader).singleton(),
87
89
  probesLoader: asFunction(probesLoader).singleton(),
88
90
  fallbackLoader: asFunction(fallbackLoader).singleton(),
89
91
  // Middlewares
@@ -1,21 +1,12 @@
1
1
  'use strict';
2
2
 
3
- module.exports = ({
4
- bodyParser: { json, urlencoded },
5
- express,
6
- compression,
7
- cors,
8
- cookieParser,
9
- prerender,
10
- config,
11
- logger,
12
- }) => {
3
+ module.exports = ({ bodyParser: { json, urlencoded }, compression, cors, cookieParser, prerender, config, logger }) => {
13
4
  const {
14
5
  BODY_PARSER_OPTIONS: { JSON_OPTIONS, URL_ENCODED_OPTIONS },
15
6
  CORS_OPTIONS,
16
7
  } = config.SERVER;
17
8
 
18
- return function load(app, { corsOptions, prerenderToken, staticFiles }) {
9
+ return function load(app, { corsOptions, prerenderToken }) {
19
10
  const childLogger = logger.where(__filename, 'load');
20
11
  childLogger.debug('Started');
21
12
  // Load useful middlewares
@@ -27,10 +18,6 @@ module.exports = ({
27
18
  if (prerenderToken) {
28
19
  app.use(prerender.set('prerenderToken', prerenderToken));
29
20
  }
30
- if (staticFiles) {
31
- const { baseUrl, folderPath } = staticFiles;
32
- app.use(baseUrl, express.static(folderPath));
33
- }
34
21
  childLogger.debug('Finished');
35
22
  };
36
23
  };
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ module.exports = ({ express, logger }) => {
4
+ return function load(app, { staticFiles }) {
5
+ const childLogger = logger.where(__filename, 'load');
6
+ childLogger.debug('Started');
7
+
8
+ if (staticFiles) {
9
+ const { baseUrl, folderPath } = staticFiles;
10
+ app.use(baseUrl, express.static(folderPath));
11
+ }
12
+ childLogger.debug('Finished');
13
+ };
14
+ };
@@ -10,6 +10,7 @@ module.exports = ({
10
10
  authorisationMiddleware,
11
11
  errorMiddleware,
12
12
  middlewaresLoader,
13
+ staticLoader,
13
14
  probesLoader,
14
15
  fallbackLoader,
15
16
  jwtService,
@@ -50,6 +51,8 @@ module.exports = ({
50
51
  if (opts.appLoader) {
51
52
  await opts.appLoader(app);
52
53
  }
54
+ // Load static files middleware
55
+ staticLoader(app, opts);
53
56
  // Load documentation
54
57
  documentationLoader(app, opts);
55
58
  // Load fallback routing