File size: 1,923 Bytes
63ec709
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import createServer from '@tomphttp/bare-server-node';
import http from 'http';
import nodeStatic from 'node-static';
//const cors = require('cors');
//const frameguard = require('frameguard') //imports iframe block
//const config = require('./config.json')
const port = process.env.PORT || 8080;
//const Corrosion = require('./lib/server')
//const btoa = e => new Buffer.from(e).toString("base64")

/*const proxy = new Corrosion({
  prefix: "/beta/",
  codec: "base64",
  title: "Classes",
  forceHttps: true,
  requestMiddleware: [
  Corrosion.middleware.blacklist([
    'accounts.google.com'
  ], 'This page is unavailable.'),
]
});*/

//proxy.bundleScripts();

const bare =  createServer('/bare/');
const serve = new nodeStatic.Server('main/');

const server = http.createServer();

//app.use(frameguard({ action: 'SAMEORIGIN' })) //blocks iframing this site

server.on('request', (req, res) => {
  if (bare.shouldRoute(req)) {
    bare.routeRequest(req, res);
  } else {
    serve.serve(req, res);
  }
});

server.on('upgrade', (req, socket, head) => {
  if (bare.shouldRoute(req, socket, head)) {
    bare.routeUpgrade(req, socket, head);
  }else{
    socket.end();
  }
});

/*app.get('/', function(req, res){
  res.sendFile('index.html', {root: './main'});
});

app.use('/g/', function(req, res, next){
  res.sendFile('gams.html', {root: './main'});
});

app.get('/js/go.js', function(req, res){
  res.sendFile('go.js', {root: './main/js/'});
});

app.get('/favicon.ico', function(req, res){
  res.sendFile('favicon.ico', {root: './main/img/'});
});

app.use(express.static('./main', {
  extensions: ['html']
}));*/

/*app.use(function (req, res) {
  if (req.url.startsWith(proxy.prefix)) {
    proxy.request(req,res);
  } else {
    res.status(404).sendFile('404.html', {root: './main'});
  }
}).post('*', (req, res) => {})*/

server.listen({
  port: port,
});

console.log(`Listening on http://localhost:${port}`)