Skip to content

Commit

Permalink
use https
Browse files Browse the repository at this point in the history
  • Loading branch information
petertimwalker committed May 24, 2024
1 parent 3d219b5 commit 6c38e1b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# npm
node_modules

.env
server.crt
server.csr
server.key
17 changes: 13 additions & 4 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const https = require('https');
const fs = require('fs');
const express = require('express');
const cors = require('cors');
const app = express();
Expand All @@ -15,17 +17,24 @@ app.use((req, res, next) => {
next();
});

// Route for the root URL '/'
app.get('/', (req, res) => {
console.log(`request from ${req}`);
res.send('Hi from api.peterwalker.xyz');
});

// Route for '/api/key'
app.get('/api/key', (req, res) => {
console.log(`request from ${req}`);
res.json({ apiKey: API_KEY });
});

app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
// HTTPS options
const options = {
key: fs.readFileSync('server.key'),
cert: fs.readFileSync('server.crt')
};

// Start the HTTPS server
https.createServer(options, app).listen(PORT, () => {
console.log(`HTTPS Server is running on port ${PORT}`);
});

0 comments on commit 6c38e1b

Please sign in to comment.