Skip to content

Commit

Permalink
hope it works now
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik Matić committed Oct 2, 2023
1 parent 5e76ea8 commit ee1c874
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
4 changes: 2 additions & 2 deletions ansible/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
state: started
restart: yes
ports:
- "80:3000"
- "443:3000"
- "80:3080"
- "443:3443"
volumes:
- "/etc/letsencrypt/:/etc/letsencrypt/"
3 changes: 2 additions & 1 deletion app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ RUN npm install

COPY --chown=node:node . .

EXPOSE 3000
EXPOSE 3080 3443


CMD [ "node", "app.js" ]
27 changes: 24 additions & 3 deletions app/app.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
const express = require('express')
const app = express()
const port = 3000
const fs = require('node:fs')
const https = require('node:https')
const http = require('node:http')
const httpsport = 3443
const httpport = 3080


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

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

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

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

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

https.createServer(options, app).listen(httpsport, () => {
console.log(`Server listening on port ${httpsport}`)
})

http.createServer(app).listen(httpport, () => {
console.log(`Http server listening on port ${httpport}`)
})

0 comments on commit ee1c874

Please sign in to comment.