3.2.14 • Published 29 days ago

dk-bff-server v3.2.14

Weekly downloads
-
License
MIT
Repository
github
Last release
29 days ago

Simple Backend-For-Frontend server

npm license

Extensible BFF server based on Express that handles static and security.

Features

  • Handles static resources with Brotli/Gzip support (should be generated by bundler)
  • Supports security rules
  • Supports HTTPS (locally) / HTTP protocols
  • Supports async template modifications for SSR
  • Restricts cache for HTML template
  • Can respond with versionIdentifier using GET /get-app-version for notifying users when new version is released
  • Handles 404 errors
  • Gathers performance metrics that could be injected in template

Usage

  1. Create file ex. ./server.ts
import path from 'path';

import { runServer } from 'dk-bff-server';

import { env } from '../env';
import { paths } from '../paths';

void runServer({
  port: env.EXPRESS_PORT, // number
  https: env.HTTPS_BY_NODE, // boolean
  templatePath: path.resolve(paths.build, 'template.html'), // path string
  staticFilesPath: paths.build, // path string
  versionIdentifier: env.GIT_COMMIT, // string
  compressedFilesGenerated: env.GENERATE_COMPRESSED, // boolean
  templateModifier: ({ template }) => {
    return Promise.resolve(
      template
        .replace(
          '<!-- HOST_DEPENDENT_CONFIG -->',
          JSON.stringify({
            API_HOST: env.API_HOST,
            IMAGE_STORAGE_URL: env.IMAGE_STORAGE_URL,
          })
        )
    );
  },
  injectMeasures: ({ template, measures }) =>
    template.replace('<!-- MEASURES -->', JSON.stringify({ server: measures }, null, 2)),
  
  customMiddlewares: [
    (app) => {
      // your middlewares
      // app.use(cookieParser());
    }
  ],

  /**
   * @docs: https://github.com/helmetjs/helmet
   * @docs: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
   */

  helmetOptions: {
    contentSecurityPolicy: {
      directives: {},
    }
  },
});
  1. Build via you bundler
  2. Start using recipe in package.json, ex.
{
  "scripts": {
    "start": "node -r dotenv/config ./build/server.js"
  }
}
3.2.9

29 days ago

3.2.13

29 days ago

3.2.12

29 days ago

3.2.14

29 days ago

3.2.11

29 days ago

3.2.10

29 days ago

3.2.8

1 month ago

3.2.7

1 month ago

3.2.6

1 month ago

3.2.6-alpha.0

1 month ago

3.2.2

1 month ago

3.2.3

1 month ago

3.2.1

1 month ago

3.2.0

1 month ago

3.1.43

3 months ago

3.1.42

3 months ago

3.1.41

3 months ago

3.1.40

3 months ago

3.1.39

3 months ago

3.1.38

4 months ago

3.1.16

10 months ago

3.1.15

10 months ago

3.1.18

10 months ago

3.1.17

10 months ago

3.1.23

9 months ago

3.1.22

10 months ago

3.1.25

9 months ago

3.1.24

9 months ago

3.1.27

7 months ago

3.1.26

9 months ago

3.1.29

7 months ago

3.1.28

7 months ago

3.1.21

10 months ago

3.1.20

10 months ago

3.1.19

10 months ago

3.1.34

6 months ago

3.1.33

6 months ago

3.1.36

5 months ago

3.1.35

6 months ago

3.1.37

5 months ago

3.1.30

7 months ago

3.1.32

6 months ago

3.1.31

6 months ago

3.1.12

11 months ago

3.1.11

11 months ago

3.1.14

11 months ago

3.1.13

11 months ago

3.1.9

11 months ago

3.1.8

11 months ago

3.0.18

11 months ago

3.0.19

11 months ago

3.0.9

11 months ago

3.0.4

11 months ago

3.1.2

11 months ago

3.0.13

11 months ago

3.1.1

11 months ago

3.0.10

11 months ago

3.1.0

11 months ago

3.0.11

11 months ago

3.1.7

11 months ago

3.0.16

11 months ago

3.0.8

11 months ago

3.1.6

11 months ago

3.0.17

11 months ago

3.0.7

11 months ago

3.1.5

11 months ago

3.0.14

11 months ago

3.0.6

11 months ago

3.1.4

11 months ago

3.0.15

11 months ago

2.2.1

1 year ago

2.1.3

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago