assets.js 609 Bytes
Newer Older
Athanasios's avatar
Athanasios committed
1
2
const express = require("express");
const path = require("path");
Athanasios's avatar
Athanasios committed
3
4
5
const BaseStorage = require('../src/baseStorage');

const storage = new BaseStorage().getInstance();
Athanasios's avatar
Athanasios committed
6
7
8
9
10
11
12

let router = express.Router();

router.route("/*")
  .get((req, res, next) => {

    let fullUrl = `${req.protocol}://${req.get("host")}${req.originalUrl}`;
Athanasios's avatar
Athanasios committed
13
    storage.isPublic(fullUrl).then(result => {
Athanasios's avatar
Athanasios committed
14
15
16
17
18
19
20
21
22
23
24
25
26
27
      if (result) {
        next();
      } else {
        return res.status(403).end("403 Forbidden")
      }
    });

  },

    express.static(path.join(__dirname, "../assets"))

  );

module.exports = router;