-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev.js
52 lines (43 loc) · 1.23 KB
/
dev.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
/** This file is only added to run a development static server. */
import path from 'path';
import { fileURLToPath } from 'url';
import os from 'os';
import fastify from 'fastify';
import fastifyStatic from '@fastify/static';
const networkInterfaces = os.networkInterfaces();
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const PORT = process.env.PORT || 3000;
const app = fastify({
logger: false,
});
app.register(fastifyStatic.default, {
root: path.join(__dirname, 'lib'),
});
app.get('/register', (req, res) => {
res.sendFile('index.html');
});
start();
showlocalNetAddress(PORT);
function showlocalNetAddress(PORT) {
console.log(`local : localhost:${PORT}/`);
const localNetAddress =
networkInterfaces?.wlp2s0?.[0]?.address ||
networkInterfaces?.enp3s0f1?.[0]?.address ||
networkInterfaces?.['Wi-Fi']?.[1]?.address ||
networkInterfaces?.Ethernet?.[1]?.address ||
null;
if (localNetAddress) {
console.log(`network : ${localNetAddress}:${PORT}/`);
} else {
console.log('network : Not Available');
}
}
async function start() {
try {
await app.listen({ port: PORT, host: '::' });
} catch (err) {
app.log.error(err);
process.exit(1);
}
}