Skip to content

Commit ee2e26e

Browse files
committed
made ready for deployment via raspberry pi
1 parent 8fa97f6 commit ee2e26e

File tree

5 files changed

+53
-5
lines changed

5 files changed

+53
-5
lines changed

.env

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
LASTFM_API_KEY=974fb2e0a3add0ac42c2729f6c1e854a
1+
PORT=3000
2+
NODE_ENV=production
3+
LASTFM_API_KEY=your_api_key

deploy.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
# Pull latest changes
4+
git pull
5+
6+
# Install dependencies
7+
npm install --production
8+
9+
# Restart PM2 process
10+
pm2 restart ecosystem.config.js

ecosystem.config.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
apps: [{
3+
name: "portfolio",
4+
script: "server.js",
5+
env: {
6+
NODE_ENV: "production",
7+
PORT: 3000
8+
},
9+
instances: 1,
10+
autorestart: true,
11+
watch: false,
12+
max_memory_restart: '200M'
13+
}]
14+
};

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"main": "server.js",
66
"scripts": {
77
"start": "node server.js",
8-
"dev": "nodemon server.js"
8+
"dev": "nodemon server.js",
9+
"deploy": "./deploy.sh"
910
},
1011
"engines": {
1112
"node": "18.x"

server.js

+24-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,23 @@ require('dotenv').config();
66
const app = express();
77
const PORT = process.env.PORT || 3000;
88

9-
// Serve static files from the root directory
10-
app.use(express.static(path.join(__dirname)));
9+
// Basic security middleware
10+
app.use((req, res, next) => {
11+
res.setHeader('X-Content-Type-Options', 'nosniff');
12+
res.setHeader('X-Frame-Options', 'DENY');
13+
res.setHeader('X-XSS-Protection', '1; mode=block');
14+
next();
15+
});
16+
17+
// Serve static files with caching
18+
app.use(express.static(path.join(__dirname), {
19+
maxAge: '1d',
20+
setHeaders: (res, path) => {
21+
if (path.endsWith('.html')) {
22+
res.setHeader('Cache-Control', 'no-cache');
23+
}
24+
}
25+
}));
1126

1227
// Serve static data files
1328
app.use('/data', express.static(path.join(__dirname, 'data')));
@@ -314,7 +329,13 @@ app.get('/api/debug/config', (req, res) => {
314329
});
315330
});
316331

332+
// Error handling
333+
app.use((err, req, res, next) => {
334+
console.error(err.stack);
335+
res.status(500).send('Something broke!');
336+
});
337+
317338
// Start the server
318-
app.listen(PORT, () => {
339+
app.listen(PORT, '0.0.0.0', () => {
319340
console.log(`Server is running on port ${PORT}`);
320341
});

0 commit comments

Comments
 (0)