29 lines
861 B
JavaScript
29 lines
861 B
JavaScript
import fs from 'fs';
|
|
import https from 'https';
|
|
import express from 'express';
|
|
import cors from 'cors';
|
|
import path from 'path';
|
|
import apiRouter from './api.js';
|
|
import { initDB } from './db.js';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.join(path.dirname(__filename), ".."); // going back a dir cuz code is in src/
|
|
const app = express();
|
|
|
|
app.use(cors());
|
|
app.use(express.json())
|
|
app.use(express.urlencoded({ extended: true }))
|
|
app.use(express.static(path.join(__dirname, "public"), {
|
|
dotfiles: "ignore"
|
|
}));
|
|
app.use("/api", apiRouter);
|
|
|
|
const options = {
|
|
key: fs.readFileSync('server.key'),
|
|
cert: fs.readFileSync('server.cert')
|
|
};
|
|
|
|
const server = https.createServer(options, app).listen(5555, () => {
|
|
console.log(`Server running on http://localhost:${server.address().port}`);
|
|
}); |