← back to Wallpaperdictionary

server.js

23 lines

const express = require('express');
const path = require('path');
const app = express();
const PORT = process.env.PORT || 9900;

// Never serve snapshot/backup files from static root
app.use((req, res, next) => {
  if (/(\.bak(\..*)?|\.pre-)/i.test(req.path)) {
    return res.status(404).type('txt').send('Not Found');
  }
  next();
});

app.use(express.static(path.join(__dirname, 'public')));

app.get('/health', (req, res) => res.json({ status: 'ok', site: 'wallpaperdictionary.com' }));

app.get('/', (req, res) => {
  res.sendFile(path.join(__dirname, 'public', 'index.html'));
});

app.listen(PORT, () => console.log(`wallpaperdictionary.com :${PORT}`));