first
This commit is contained in:
33
server.js
Normal file
33
server.js
Normal file
@ -0,0 +1,33 @@
|
||||
import jsonServer from "json-server";
|
||||
import db from "./db/index.js";
|
||||
import https from "https";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
const server = jsonServer.create();
|
||||
const PORT = 4000;
|
||||
|
||||
const keyFile = path.join(__dirname, "/certs/localhost-key.pem");
|
||||
const certFile = path.join(__dirname, "/certs/localhost.pem");
|
||||
|
||||
const router = jsonServer.router(db);
|
||||
const middleware = jsonServer.defaults();
|
||||
|
||||
server.use(middleware);
|
||||
server.use("/api", router);
|
||||
|
||||
https
|
||||
.createServer(
|
||||
{
|
||||
key: fs.readFileSync(keyFile),
|
||||
cert: fs.readFileSync(certFile),
|
||||
},
|
||||
server
|
||||
)
|
||||
.listen(PORT, () => {
|
||||
console.log(`Go to https://localhost:${PORT}/`);
|
||||
});
|
Reference in New Issue
Block a user