* chore: expose fs apis * chore: correct electron import path * update download api Signed-off-by: James <james@jan.ai> * update chat_completion Signed-off-by: James <james@jan.ai> * fix electron import Signed-off-by: James <james@jan.ai> * feat: adding API support at 1337 (#991) Signed-off-by: James <james@jan.ai> Co-authored-by: James <james@jan.ai> * feat: Add /chat/completion api and handler * chore: add todo for modelList * chore: read engine.json for openai chat_completion (#1030) Signed-off-by: James <james@jan.ai> Co-authored-by: James <james@jan.ai> * refactor: move routes to shared node module * refactor: exported modules from core with types (#1172) * refactor: exported modules from core with types * fix: fix file reading args * refactor: fileManager handles * fix: app issues with server refactoring * refactor: shared server module (#1210) * chore: resolve main * chore: update makefile --------- Signed-off-by: James <james@jan.ai> Co-authored-by: James <james@jan.ai> Co-authored-by: NamH <NamNh0122@gmail.com> Co-authored-by: hiro <vuonghoainam.work@gmail.com>
44 lines
1003 B
TypeScript
44 lines
1003 B
TypeScript
import fastify from "fastify";
|
|
import dotenv from "dotenv";
|
|
import { v1Router } from "@janhq/core/node";
|
|
import path from "path";
|
|
|
|
dotenv.config();
|
|
|
|
const JAN_API_HOST = process.env.JAN_API_HOST || "0.0.0.0";
|
|
const JAN_API_PORT = Number.parseInt(process.env.JAN_API_PORT || "1337");
|
|
|
|
const server = fastify();
|
|
server.register(require("@fastify/cors"), {});
|
|
server.register(
|
|
(childContext, _, done) => {
|
|
childContext.register(require("@fastify/static"), {
|
|
root:
|
|
process.env.EXTENSION_ROOT ||
|
|
path.join(require("os").homedir(), "jan", "extensions"),
|
|
wildcard: false,
|
|
});
|
|
|
|
done();
|
|
},
|
|
{ prefix: "extensions" }
|
|
);
|
|
server.register(v1Router, { prefix: "/v1" });
|
|
|
|
export const startServer = () => {
|
|
server
|
|
.listen({
|
|
port: JAN_API_PORT,
|
|
host: JAN_API_HOST,
|
|
})
|
|
.then(() => {
|
|
console.log(
|
|
`JAN API listening at: http://${JAN_API_HOST}:${JAN_API_PORT}`
|
|
);
|
|
});
|
|
};
|
|
|
|
export const stopServer = () => {
|
|
server.close();
|
|
};
|