add https settings and service

This commit is contained in:
2017-02-23 14:06:03 +07:00
parent f28ab5f2b9
commit ad719d397b
2 changed files with 26 additions and 0 deletions

13
app.js
View File

@@ -1,9 +1,18 @@
var express = require('express');
var bodyParser = require('body-parser');
var https = require('https');
var fs = require('fs');
var zmrBot = require('./bot.js');
var app = express();
var port = process.env.PORT || 3000;
var sslPath = '/etc/letsencrypt/live/sao.twilightparadox.com/';
var options = {
key: fs.readFileSync(sslPath + 'privkey.pem'),
cert: fs.readFileSync(sslPath + 'fullchain.pem')
};
// body parser middleware
app.use(bodyParser.urlencoded({ extended: true }));
@@ -19,6 +28,10 @@ app.use(function (err, req, res, next) {
res.status(400).send(err.message);
});
var server = http.createServer(options, app);
var io = require('socket.io').listen(server);
server.listen(443);
app.listen(port, function () {
console.log('Slack bot listening on port ' + port);
});

13
slackbot.service Normal file
View File

@@ -0,0 +1,13 @@
[Unit]
Description=Your app
After=network.target
[Service]
ExecStart=/var/www/myapp/app.js
Restart=always
User=nobody
Group=nobody
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production
WorkingDirectory=/var/www/myapp
[Install]
WantedBy=multi-user.target