This repository has been archived by the owner on Apr 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
66 lines (54 loc) · 1.49 KB
/
index.js
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
import createBareServer from '@tomphttp/bare-server-node';
import express from 'express';
import http from 'node:http';
import webpack from 'webpack';
import * as path from 'path';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url))
var bundle = webpack({
mode: 'development',
entry: {
MAIN: path.join(__dirname, '/src/main.js'),
SW: path.join(__dirname, '/src/sw.js'),
WORKER: path.join(__dirname, '/src/worker.js'),
CLIENT: path.join(__dirname, '/src/client/')
},
output: {
path: path.join(__dirname, '/public/eclipse'),
filename: 'EC.[name].js'
}
});
bundle.watch(true, (error)=>{
if (error) {
console.log("Error: ", error);
} else {
console.log("Bundled Eclipse");
}
})
const httpServer = http.createServer();
const app = express();
app.get("/", (req, res) => {
res.sendFile(__dirname + "/public/index.html");
});
app.use(express.static(__dirname + "/public"))
const bareServer = createBareServer('/bare/');
httpServer.on("request", (req, res) => {
if (bareServer.shouldRoute(req)) {
bareServer.routeRequest(req, res);
} else {
app(req, res);
}
});
httpServer.on("upgrade", (req, socket, head) => {
if (bareServer.shouldRoute(req)) {
bareServer.routeUpgrade(req, socket, head);
} else {
socket.end();
}
});
httpServer.on("listening", () => {
console.log("Eclipse in running on port 8080");
});
httpServer.listen({
port: 8080,
});