aboutsummaryrefslogtreecommitdiffstats
path: root/mascara/server/index.js
blob: 0f9b047a7a4d248e57372c788a4a7dd53d3a588b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const path = require('path')
const express = require('express')
const createBundle = require('./util').createBundle
const serveBundle = require('./util').serveBundle
const compression = require('compression')

module.exports = createMetamascaraServer


function createMetamascaraServer () {

  // start bundlers
  const metamascaraBundle = createBundle(path.join(__dirname, '/../src/mascara.js'))
  const proxyBundle = createBundle(path.join(__dirname, '/../src/proxy.js'))
  const uiBundle = createBundle(path.join(__dirname, '/../src/ui.js'))
  const backgroundBuild = createBundle(path.join(__dirname, '/../src/background.js'))

  // serve bundles
  const server = express()
  server.use(compression())

  // ui window
  serveBundle(server, '/scripts/ui.js', uiBundle)
  server.use(express.static(path.join(__dirname, '/../ui/'), { setHeaders: (res) => res.set('X-Frame-Options', 'DENY') }))
  server.use(express.static(path.join(__dirname, '/../../dist/chrome')))
  // metamascara
  serveBundle(server, '/metamascara.js', metamascaraBundle)
  // proxy
  serveBundle(server, '/scripts/proxy.js', proxyBundle)
  server.use('/', express.static(path.join(__dirname, '/../proxy')))
  // background
  serveBundle(server, '/scripts/background.js', backgroundBuild)

  return server

}