Add .env support for configurable Name and Slogan in preview cards
NAME and SLOGAN are read from .env via dotenv and injected into the LinkedIn preview card template at startup. Avatar initials are auto- generated from the first letters of NAME. Works identically with npm start and docker compose (via env_file). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
14
server.js
14
server.js
@@ -1,14 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
require('dotenv').config();
|
||||
const express = require('express');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 3000;
|
||||
|
||||
const NAME = process.env.NAME || 'Name';
|
||||
const SLOGAN = process.env.SLOGAN || '';
|
||||
const INITIALS = NAME.split(' ').map(w => w[0]).join('').slice(0, 2).toUpperCase();
|
||||
|
||||
app.use(express.static(path.join(__dirname, 'public')));
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
res.sendFile(path.join(__dirname, 'public', 'index.html'));
|
||||
let html = fs.readFileSync(path.join(__dirname, 'public', 'index.html'), 'utf8');
|
||||
html = html
|
||||
.replace('{{INITIALS}}', INITIALS)
|
||||
.replace('{{NAME}}', NAME)
|
||||
.replace('{{SLOGAN}}', SLOGAN);
|
||||
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
||||
res.send(html);
|
||||
});
|
||||
|
||||
app.listen(PORT, () => {
|
||||
|
||||
Reference in New Issue
Block a user