Skip to content
This repository was archived by the owner on Dec 9, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions config.sample.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
config = {
mongodb_server_url: 'mongodb://127.0.0.1:27017/ptpush',
server_port: 3000,
/* enable_https: true,
private_key_path: './cert/private.pem',
certificate_path: './cert/file.crt', */
/* auth: {
"file": ""
}, */
server_port: 3000
certificate_path: './cert/file.crt' */
}

module.exports = config;
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"mongoose": "^4.11.7",
"node-schedule": "^1.2.4",
"request": "^2.81.0",
"request-promise-native": "^1.0.4",
"http-auth": "^3.2.3"
"request-promise-native": "^1.0.4"
}
}
19 changes: 2 additions & 17 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const express = require('express');
const Http = require('http');
const Https = require('https');
var auth = require('http-auth');
const fs = require('fs');
const mongoose = require('mongoose');
const subscribeapi = require('./subscribeapi');
Expand Down Expand Up @@ -35,29 +34,15 @@ mongoose.connect(DB_URL, { useMongoClient: true }).then(
let certificate = fs.readFileSync(Config.certificate_path, 'utf8');
let credentials = {key: privateKey, cert: certificate};

if (!Config.auth) {
let basicAuth = auth.basic(Config.auth);
let httpsServer = Https.createServer(basicAuth, credentials, app);
console.log("Http authorization is enabled.");
} else {
let httpsServer = Https.createServer(credentials, app);
}

let httpsServer = Https.createServer(credentials, app);
httpsServer.listen(Config.server_port, () => {
let host = httpsServer.address().address;
let port = httpsServer.address().port;

console.log("Https Server running at https://%s:%s", host, port);
});
} else {
if (!Config.auth) {
let basicAuth = auth.basic(Config.auth);
let httpServer = Http.createServer(basicAuth, app);
console.log("Http authorization is enabled.");
} else {
let httpServer = Http.createServer(app);
}

let httpServer = Http.createServer(app);
httpServer.listen(Config.server_port, () => {
let host = httpServer.address().address;
let port = httpServer.address().port;
Expand Down