forked from emranio/ai-chat-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
35 lines (31 loc) · 949 Bytes
/
server.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
import Fastify from "fastify";
import { fileURLToPath } from "url"
import { dirname, join } from "path"
import dotenv from "dotenv";
import autoLoad from "@fastify/autoload";
import fastifyMultipart from "@fastify/multipart";
dotenv.config();
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename);
const PORT = process.env.PORT || 4000;
const HOST = "0.0.0.0";
const server = Fastify({
ignoreTrailingSlash: true,
logger: true,
});
server.register(fastifyMultipart, {
limits: {
fieldNameSize: 20,
fileSize: 1000000
}
});
server.register(autoLoad, { dir: join(__dirname, 'src', 'routes') });
server.register(autoLoad, { dir: join(__dirname, 'src', 'config') });
server.listen({ host: HOST, port: +PORT }, (err, address) => {
if (err) {
server.log.error(err);
console.log(err);
process.exit(1);
}
console.log(`Server listening at ${address}`)
});