Skip to content

Commit

Permalink
Merge pull request #19 from DIG-Network/release/v0.0.1-alpha.20
Browse files Browse the repository at this point in the history
Release/v0.0.1 alpha.20
  • Loading branch information
MichaelTaylor3D authored Sep 16, 2024
2 parents ce07a48 + d314c51 commit e567f0e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 12 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [0.0.1-alpha.20](https://github.com/DIG-Network/dig-content-server/compare/v0.0.1-alpha.19...v0.0.1-alpha.20) (2024-09-16)


### Bug Fixes

* ssl cert ([a8b1f84](https://github.com/DIG-Network/dig-content-server/commit/a8b1f84592d2cb2b505a9f63af1e7b12c9eb36ca))

### [0.0.1-alpha.19](https://github.com/DIG-Network/dig-content-server/compare/v0.0.1-alpha.18...v0.0.1-alpha.19) (2024-09-16)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dig-content-server",
"version": "0.0.1-alpha.19",
"version": "0.0.1-alpha.20",
"description": "",
"type": "commonjs",
"main": "./dist/index.js",
Expand Down
55 changes: 46 additions & 9 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,56 @@
import express from "express";
import { storeRoutes } from "./routes";
import cookieParser from "cookie-parser";
import cors from "cors";
import express from "express";
import https from "https";
import fs from "fs";
import path from "path";
import { storeRoutes } from "./routes";
import { Tls } from "chia-server-coin";

const caCertPath = path.join(__dirname, "ssl", "ca", "chia_ca.crt");
const caKeyPath = path.join(__dirname, "ssl", "ca", "chia_ca.key");

const serverCertPath = path.join(__dirname, "ssl", "dig", "server.cert");
const serverKeyPath = path.join(__dirname, "ssl", "dig", "server.key");

if (!fs.existsSync(caCertPath) || !fs.existsSync(caKeyPath)) {
throw new Error("CA certificate or key not found.");
}

// Ensure the directory for server certificate and key exists
const serverDir = path.dirname(serverCertPath);
if (!fs.existsSync(serverDir)) {
fs.mkdirSync(serverDir, { recursive: true });
}

if (!fs.existsSync(serverCertPath) || !fs.existsSync(serverKeyPath)) {
// Ensure that the Tls class will generate certs correctly, signed by your CA.
new Tls(serverCertPath, serverKeyPath);
console.log("Server certificate and key generated successfully.");
}

const caCert = fs.readFileSync(caCertPath);
const serverCert = fs.readFileSync(serverCertPath);
const serverKey = fs.readFileSync(serverKeyPath);

const app = express();
const PORT = process.env.PORT || 3000;
const PORT = Number(process.env.PORT) || 4161;

// Apply store routes
app.use(cookieParser());
app.use(cors());

app.use("/", storeRoutes);

app.use((req, res, next) => {
res.setHeader("Referrer-Policy", "same-origin");
next();
});
const serverOptions = {
key: serverKey,
cert: serverCert,
ca: caCert,
requestCert: true, // Require client certificate
rejectUnauthorized: true, // Reject unauthorized clients
};

// Create the HTTPS server
const server = https.createServer(serverOptions, app);

export { app, PORT };
// Export both the app and the server
export { app, server, PORT };

0 comments on commit e567f0e

Please sign in to comment.