-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.cjs
54 lines (43 loc) · 1.49 KB
/
index.cjs
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
const express = require("express");
const app = express();
const cors = require("cors");
const bodyParser = require("body-parser");
const { generateAccessToken, auth } = require("./utils/auth.cjs");
const path = require("path");
const { exec } = require('child_process');
const corsOptions = {
origin: "*",
};
app.use(cors(corsOptions));
app.use(bodyParser.json());
// Serve static files from the 'portal' directory
app.use(express.static(path.join(__dirname, "portal")));
// Handle all routes by serving the 'index.html' file
app.get("/portal", (req, res) => {
res.sendFile(path.join(__dirname, "portal", "index.html"));
});
const jabDBRoute = require("./core/actions/index.cjs");
import('./portal/index.js')
app.use("/", auth, jabDBRoute);
const jabulaneDB = (port = 0) => {
const server = app.listen(port, () => {
const { port } = server.address();
const token = generateAccessToken();
console.log(
`Jabulane-db: Database is running on port ${port}. access it on key is ${token}`
);
// Specify the URL you want to open
const urlToOpen = `http://localhost:3003/landing/${port}/${token}`;
console.log(`Open ${urlToOpen} in the default web browser`);
(`open ${urlToOpen}`, (error, stdout, stderr) => {
if (error) {
console.error(`Error opening ${urlToOpen}: ${error.message}`);
return;
}
console.log(`Opened ${urlToOpen} in the default web browser`);
});
});
return server;
};
jabulaneDB();
module.exports = jabulaneDB;