Passed
Pull Request — master (#277)
by
unknown
01:48
created

client/legacy/src/server.js   A

Complexity

Total Complexity 4
Complexity/F 1

Size

Lines of Code 43
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 33
mnd 0
bc 0
fnc 4
dl 0
loc 43
bpm 0
cpm 1
noi 0
c 0
b 0
f 0
rs 10
1
import sirv from 'sirv';
2
import express from 'express';
3
import compression from 'compression';
4
import cookieParser from 'cookie-parser';
5
import * as sapper from '@sapper/server';
6
import { guard } from '@beyonk/sapper-rbac';
7
import routes from './routes';
8
import authMiddleware from './middlewares/auth';
9
import './i18n';
10
11
const { PORT, NODE_ENV } = process.env;
12
const dev = NODE_ENV === 'development';
13
const app = express();
14
15
app
16
  .use(
17
    cookieParser(),
18
    compression({ threshold: 0 }),
19
    sirv('static', { dev }),
20
    authMiddleware,
21
    (req, res, next) => {
22
      const { user } = req;
23
      const options = {
24
        routes,
25
        deny: () => {
26
          res.redirect('/login');
27
          return res.end();
28
        },
29
        grant: () => {
30
          return sapper.middleware({
31
            session: () => {
32
              return {
33
                user,
34
              };
35
            },
36
          })(req, res, next);
37
        },
38
      };
39
40
      return guard(req.path, user, options);
41
    }
42
  )
43
  .listen(PORT);
44