-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathserver.mjs
34 lines (31 loc) · 1001 Bytes
/
server.mjs
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
import { startAppServer } from './server/app.mjs';
import open from 'open';
import dotenv from 'dotenv';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
dotenv.config({ path: ['.env', '.env.local'] });
const dev = process.env.NODE_ENV !== 'production';
const hostname = 'localhost';
const port = parseInt(process.env.GPTSCRIPT_PORT ?? '3000');
const appDir = dirname(fileURLToPath(import.meta.url));
const runFile = process.env.UI_RUN_FILE;
startAppServer({ dev, hostname, port, appDir })
.then((address) => {
let landingPage = address;
if (runFile) {
landingPage = `${landingPage}/?file=${runFile}`;
}
open(landingPage)
.then(() => {
console.log(`${landingPage} opened!`);
})
.catch((err) => {
console.error(
`Failed to open landing page ${landingPage}: ${err.message}`
);
});
})
.catch((err) => {
console.error(`Failed to start app server: ${err.message}`);
process.exit(1);
});