Commit 71dc933f authored by yPhil's avatar yPhil
Browse files

https server tests

parent 1ad22933
Pipeline #398127 failed with stage
in 57 seconds
#!/usr/bin/env node
const petrolette = require('../petrolette'),
debug = require('debug')('petrolette:server'),
path = require('path'),
http = require('http'),
fs = require('fs'),
port = normalizePort('8000');
https = require('https'),
fs = require('fs');
petrolette.set('port', port);
const httpsServer = https.createServer({
key: fs.readFileSync(path.join(__dirname, '../cert/privkey.pem'), 'utf8'),
cert: fs.readFileSync(path.join(__dirname, '../cert/cert.pem'), 'utf8'),
}, petrolette);
function isLocal() {
switch( window.location.protocol ) {
case 'file:':
return true;
default:
return false;
}
}
var httpServer = http.createServer(petrolette);
// console.log('### ENV: ' + process.env.NODE_ENV);
// console.log('## PORT: ' + port);
httpServer.listen(8000, () => {
console.error('HTTP Server running');
});
// if (!isLocal) {
// const options = {
// cert: fs.readFileSync('../cert/fullchain.pem'),
// key: fs.readFileSync('../cert/privkey.pem')
// };
// } else {
// const options
// }
// const options = isLocal() ? '' : {cert: fs.readFileSync('../cert/fullchain.pem'), key: fs.readFileSync('../cert/privkey.pem')};
var server = http.createServer(petrolette);
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
function normalizePort(val) {
var port = parseInt(val, 10);
if (isNaN(port)) {
// named pipe
return val;
}
if (port >= 0) {
// port number
return port;
}
return false;
}
/**
* Event listener for HTTP server "error" event.
*/
function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}
var bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port;
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error('## ' + bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error('## ' + bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}
/**
* Event listener for HTTP server "listening" event.
*/
function onListening() {
var addr = server.address();
var bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port;
debug('Listening on ' + bind);
}
httpsServer.listen(443, () => {
console.log('HTTPS Server running');
});
{
"name": "petrolette",
"version": "1.1.2",
"version": "1.2.2",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"version": "1.1.2",
"version": "1.2.2",
"hasInstallScript": true,
"license": "GPL-3.0-only",
"dependencies": {
"body-parser": "^1.19.0",
"bower": "^1.8.12",
"compression": "^1.7.4",
"cors": "^2.8.5",
"ejs": "^3.1.5",
"express": "^4.17.1",
"favrat": "git+https://framagit.org/yphil/favrat.git",
......@@ -1582,6 +1583,18 @@
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
},
"node_modules/cors": {
"version": "2.8.5",
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
"dependencies": {
"object-assign": "^4",
"vary": "^1"
},
"engines": {
"node": ">= 0.10"
}
},
"node_modules/cron": {
"version": "1.8.2",
"resolved": "https://registry.npmjs.org/cron/-/cron-1.8.2.tgz",
......@@ -6564,6 +6577,14 @@
"node": "*"
}
},
"node_modules/object-assign": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
"integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/on-finished": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz",
......@@ -6863,9 +6884,9 @@
}
},
"node_modules/pm2": {
"version": "4.5.4",
"resolved": "https://registry.npmjs.org/pm2/-/pm2-4.5.4.tgz",
"integrity": "sha512-2xKXrKz21i1R3BK2XxVIPq5Iy9fKHBVgZ+KMfRrx72mc7bq84SG/D+iTO32ihLf2Qe+N1o8rDskAt4M30JWyiA==",
"version": "4.5.5",
"resolved": "https://registry.npmjs.org/pm2/-/pm2-4.5.5.tgz",
"integrity": "sha512-feLYWAq8liDsM2IV0ViZ4TSnEUoOtpuICakzFnhh2bb51BUnpJMOjO1sojR1jDuNHvhrYGWqneOUglxE6slKwg==",
"dependencies": {
"@pm2/agent": "~1.0.4",
"@pm2/io": "~4.3.5",
......@@ -6879,7 +6900,7 @@
"commander": "2.15.1",
"cron": "1.8.2",
"dayjs": "~1.8.25",
"debug": "^4.3.0",
"debug": "^4.3.1",
"enquirer": "2.3.6",
"eventemitter2": "5.0.1",
"fclone": "1.0.11",
......@@ -6906,9 +6927,6 @@
},
"engines": {
"node": ">=8.10.0"
},
"optionalDependencies": {
"systeminformation": "^4.32"
}
},
"node_modules/pm2-axon": {
......@@ -7817,31 +7835,6 @@
"node": ">=4"
}
},
"node_modules/systeminformation": {
"version": "4.34.15",
"resolved": "https://registry.npmjs.org/systeminformation/-/systeminformation-4.34.15.tgz",
"integrity": "sha512-GRm0ntHg/MTISxZSu7r0T8reU1LLXUZxMcuDnqCcxIP0V+vjrt7SsiTWKrlsiL/DnThgUQHo1PT7VlZ5aKxdlQ==",
"optional": true,
"os": [
"darwin",
"linux",
"win32",
"freebsd",
"openbsd",
"netbsd",
"sunos"
],
"bin": {
"systeminformation": "lib/cli.js"
},
"engines": {
"node": ">=4.0.0"
},
"funding": {
"type": "Buy me a coffee",
"url": "https://www.buymeacoffee.com/systeminfo"
}
},
"node_modules/test-exclude": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz",
......@@ -9716,6 +9709,15 @@
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
},
"cors": {
"version": "2.8.5",
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
"requires": {
"object-assign": "^4",
"vary": "^1"
}
},
"cron": {
"version": "1.8.2",
"resolved": "https://registry.npmjs.org/cron/-/cron-1.8.2.tgz",
......@@ -13287,6 +13289,11 @@
"resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz",
"integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ=="
},
"object-assign": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
"integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM="
},
"on-finished": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz",
......@@ -13532,9 +13539,9 @@
}
},
"pm2": {
"version": "4.5.4",
"resolved": "https://registry.npmjs.org/pm2/-/pm2-4.5.4.tgz",
"integrity": "sha512-2xKXrKz21i1R3BK2XxVIPq5Iy9fKHBVgZ+KMfRrx72mc7bq84SG/D+iTO32ihLf2Qe+N1o8rDskAt4M30JWyiA==",
"version": "4.5.5",
"resolved": "https://registry.npmjs.org/pm2/-/pm2-4.5.5.tgz",
"integrity": "sha512-feLYWAq8liDsM2IV0ViZ4TSnEUoOtpuICakzFnhh2bb51BUnpJMOjO1sojR1jDuNHvhrYGWqneOUglxE6slKwg==",
"requires": {
"@pm2/agent": "~1.0.4",
"@pm2/io": "~4.3.5",
......@@ -13548,7 +13555,7 @@
"commander": "2.15.1",
"cron": "1.8.2",
"dayjs": "~1.8.25",
"debug": "^4.3.0",
"debug": "^4.3.1",
"enquirer": "2.3.6",
"eventemitter2": "5.0.1",
"fclone": "1.0.11",
......@@ -13564,7 +13571,6 @@
"semver": "^7.2",
"source-map-support": "0.5.19",
"sprintf-js": "1.1.2",
"systeminformation": "^4.32",
"vizion": "2.2.1",
"yamljs": "0.3.0"
},
......@@ -14301,12 +14307,6 @@
"has-flag": "^3.0.0"
}
},
"systeminformation": {
"version": "4.34.15",
"resolved": "https://registry.npmjs.org/systeminformation/-/systeminformation-4.34.15.tgz",
"integrity": "sha512-GRm0ntHg/MTISxZSu7r0T8reU1LLXUZxMcuDnqCcxIP0V+vjrt7SsiTWKrlsiL/DnThgUQHo1PT7VlZ5aKxdlQ==",
"optional": true
},
"test-exclude": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz",
......
......@@ -28,6 +28,7 @@
"body-parser": "^1.19.0",
"bower": "^1.8.12",
"compression": "^1.7.4",
"cors": "^2.8.5",
"ejs": "^3.1.5",
"express": "^4.17.1",
"favrat": "git+https://framagit.org/yphil/favrat.git",
......
......@@ -5,6 +5,7 @@ const express = require('express'),
pjson = require('./package.json'),
bodyParser = require('body-parser'),
app = express(),
cors = require('cors'),
helmet = require("helmet"),
compression = require('compression');
......@@ -23,9 +24,14 @@ app.use(compression());
app.use('/favicons', express.static(path.join(__dirname, pjson.FAVICONS_CACHE_DIR)));
app.use('/static', express.static(path.join(__dirname, 'public')));
app.use('/bower', express.static(path.join(__dirname, 'bower_components')));
app.use('/', router);
// app.use(express.static(__dirname, { dotfiles: 'allow' } ));
// app.listen(80, () => {
// console.log('HTTP server running on port 80');
// });
app.use(helmet.originAgentCluster());
app.use(helmet.noSniff());
app.use(bodyParser.json());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment