Completed
Push — master ( 0de142...8b6d6f )
by Mathieu
16s queued 11s
created

client/src/server.js   A

Complexity

Total Complexity 4
Complexity/F 1

Size

Lines of Code 40
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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