-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.mjs
58 lines (49 loc) · 1.42 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import Fastify from 'fastify';
import fastifyWebsocket from '@fastify/websocket';
import fastifyStatic from '@fastify/static';
import fastifyEnv from '@fastify/env';
import path from 'node:path';
import { fileURLToPath } from 'url';
import fs from 'node:fs';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
import claimsRoute from './routes/claims-route.mjs';
import chatbotWSRoute from './routes/chatbot-ws-route.mjs';
import sqliteConnector from './plugins/db/sqlite-connector.mjs';
// Setup Logging
const fastify = Fastify({
logger: true
});
// Register the Fastify ENV plugin for reading the .env files
await fastify.register(fastifyEnv, {
schema: {
type: 'object'
},
dotenv: true
});
// WebUI related setup and serving
const webuiLocation = '../parasol-insurance/app/src/main/webui/dist';
fastify.register(fastifyStatic, {
wildcard: false,
root: path.join(__dirname, webuiLocation)
});
fastify.get('/*', (req, res) => {
res.send(fs.createReadStream(path.join(__dirname, webuiLocation, 'index.html')));
});
// Register plugins and Routes
fastify.register(sqliteConnector);
fastify.register(fastifyWebsocket);
fastify.register(claimsRoute);
fastify.register(chatbotWSRoute);
/**
* Run the server!
*/
const start = async () => {
try {
await fastify.listen({ port: process.env.PORT || 8005 })
} catch (err) {
fastify.log.error(err)
process.exit(1)
}
};
start();