Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik Matić committed Oct 2, 2023
1 parent 877cd96 commit adacb16
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
7 changes: 3 additions & 4 deletions ansible/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
force_source: true

- name: (re)start a container
docker_container:
community.docker.docker_container:
name: my_website
image: dominikmatic/my_website:latest
state: started
restart: yes
ports:
- "80:3000"
- "443:3000"
mounts:
- source: /etc/letsencrypt/
target: /etc/letsencrypt/
volumes:
- "/etc/letsencrypt/:/etc/letsencrypt/"
14 changes: 13 additions & 1 deletion app/app.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
const express = require('express')
const app = express()
const fs = require('fs')
const https = require('https')
const port = 3000

app.set('view engine', 'ejs')

app.use(express.static(__dirname + '/public'));

app.use((req, res, next) => {
if(req.protocol === 'http') {
return res.redirect(301, `https://${req.headers.host}${req.url}`);
}
next();
})

app.get('/', (req, res) => {
res.render('index.ejs')
Expand All @@ -19,6 +27,10 @@ app.get('/mylinks', (req, res) => {
res.render('mylinks.ejs')
})

app.listen(port, () => {
https.createServer({
key: fs.readFileSync('/etc/letsencrypt/private.key.pem'),
cert: fs.readFileSync('/etc/letsencrypt/domain.cert.pem'),
ca: fs.readFileSync('/etc/letsencrypt/intermediate.cert.pem')
}).listen(port, () => {
console.log(`Server listening on port ${port}`)
})

0 comments on commit adacb16

Please sign in to comment.