Compare commits

...

10 commits

Author SHA1 Message Date
root
2c0671e870 Initial commit: contact-form 2026-06-23 20:27:45 +00:00
cws
35cac6560b spell check passed 2020-02-02 13:41:33 +01:00
cws
aadeac6695 minor changes 2020-02-02 13:19:52 +01:00
cws
fbaa65d10a minor changes 2020-02-02 13:18:45 +01:00
cws
2224841564 minor mods 2020-02-02 13:08:23 +01:00
cws
aac4ed731b enhance description 2020-02-02 13:02:33 +01:00
cws
acd510b1d6 enhance description 2020-02-02 13:00:49 +01:00
cws
c33b5ac2a8 add link 2020-02-01 18:57:59 +01:00
cws
8e631c436a add link 2020-02-01 18:55:47 +01:00
cws
3d9d14705a minor fixes 2020-02-01 18:51:37 +01:00
7 changed files with 152 additions and 25 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@ node_modules
package.json
package-lock.json
assets/js/validate.min.js
assets/public

18
Dockerfile Normal file
View file

@ -0,0 +1,18 @@
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
# Use --omit=dev instead of deprecated --production flag
RUN npm install --omit=dev
COPY . .
EXPOSE 7000
RUN addgroup -S contactform && adduser -S contactform -G contactform
RUN chown -R contactform:contactform /app
USER contactform
CMD ["node", "ghost-contact-svc.js"]

View file

@ -1,5 +1,10 @@
# ghost-contact-form
Contact Forms in Ghost — Without External Services
Add a beautiful, fully functional contact form to your Ghost blog or website without paying for external services.
*Not running on Ghost?* This solution also works with Gatsby, Hugo, Hexo, Nuxt and any other static site generator.
## Tutorial
- [Contact Forms in Ghost](https://atmolabs.org/contact-forms-in-ghost/)
## Prerequisites
- A supported version of Node.js
@ -26,14 +31,23 @@ EMAIL_FROM = noreply@your-blog.com
EMAIL_TO = your@email.com
```
Additionally, you can add a port variable `PORT = `, if you want to change the default port `7000` to something else.
## Usage
```
$ node ghost-contact-svc.js
```
You should see the message `Listening on http://localhost:7000`.
## Test Locally
```
$ http://lcoalhost:7000/v1/demo
```
[http://localhost:7000/v1/demo](http://localhost:7000/v1/demo)
## Deploy (More detailed info in the tutorial)
- copy the work folder `ghost-contact-form` to your server
- use `ghost-contact.service` as a starting point for running `ghost-contact-svc.js` as a systemd daemon
- configure your web-server to map endpoint `http://localhost:7000/` to a public endpoint, e.g. `https://api.your-blog.com/`
- Use the files in folder `ghost-admin` to configure your Ghost front-end
- Other front-end configuration files upon request!

53
README.md.bak Normal file
View file

@ -0,0 +1,53 @@
# ghost-contact-form
Add a beautiful, fully functional contact form to your Ghost blog or website without paying for external services.
*Not running on Ghost?* This solution also works with Gatsby, Hugo, Hexo, Nuxt and any other static site generator.
## Tutorial
- [Contact Forms in Ghost](https://atmolabs.org/contact-forms-in-ghost/)
## Prerequisites
- A supported version of Node.js
- npm to manage packages
## Quickstart Install
```
$ git clone https://github.com/styxlab/ghost-contact-form.git
$ cd ghost-contact-form
$ sh install.sh
```
## Configure
Adapt the `.env` file to your needs. The following variables must be defined.
```
SMTP_HOST = mail.server.com
SMTP_USER = user@server.com
SMTP_PASS = strong password
ALLOW_ORIGIN = https://your-blog.com
EMAIL_FROM = noreply@your-blog.com
EMAIL_TO = your@email.com
```
Additionally, you can add a port vairable `PORT = `, if you want to change thedefault port `7000` to something else.
## Usage
```
$ node ghost-contact-svc.js
```
You should see the message `Listening on http://localhost:7000`.
## Test Locally
[http://localhost:7000/v1/demo](http://localhost:7000/v1/demo)
## Deploy (More detailed info in the tutorial)
- copy the work folder `ghost-contact-form` to your server
- use `ghost-contact.service` as a starting point for running `ghost-contact-svc.js` as a systemd deamon
- configure your webserver to map endpoint `http://localhost:7000/` to a public endpoint, e.g. `https://api.your-blog.com/`
- Use the files in folder `ghost-admin` to configure your Ghost front-end
- Other front-end config files upon request!

View file

@ -34,8 +34,7 @@ body {
.header {
position: fixed;
top: 0;
left: 50%;
margin-left: -480px;
margin-left: 100px;
background-color: #fff;
border-bottom: 1px solid #ddd;
padding-top: 10px;

48
docker-compose.yml Normal file
View file

@ -0,0 +1,48 @@
services:
contact-form:
build: .
container_name: contact-form
restart: unless-stopped
# Only expose to localhost - nginx will proxy
ports:
- "127.0.0.1:7000:7000"
env_file:
- .env
# Security hardening
security_opt:
- no-new-privileges:true
read_only: true
tmpfs:
- /tmp
networks:
contact-form-net:
mailcow-network:
ipv4_address: 172.22.1.243
# Resource limits
deploy:
resources:
limits:
cpus: '0.25'
memory: 128M
reservations:
memory: 64M
healthcheck:
test: ["CMD", "wget", "--quiet", "--tries=1",
"--spider", "http://localhost:7000/v1/demo"]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
networks:
contact-form-net:
driver: bridge
mailcow-network:
external: true
name: mailcowdockerized_mailcow-network

View file

@ -8,7 +8,7 @@ var smtpTrans = require('nodemailer-smtp-transport');
var validator = require("email-validator");
var sanitize = require('sanitize-html');
var smtp = { "auth": {}, "port": 465, "secure": true, "tls": {"rejectUnauthorized": false}, "debug": false};
var smtp = { "auth": {}, "port": 587, "secure": false, "tls": {"rejectUnauthorized": false}, "debug": false};
smtp.host = process.env.SMTP_HOST;
smtp.auth.user = process.env.SMTP_USER;
smtp.auth.pass = process.env.SMTP_PASS;
@ -18,9 +18,9 @@ var app = express();
app.disable('x-powered-by');
app.use(bodyParser.urlencoded({limit: '1mb', extended: false}));
app.use(bodyParser.json({limit: '1mb'}));
app.use(cors({origin: process.env.ALLOW_ORIGIN,
allowedHeaders: ['Content-Type', 'application/json; charset=utf-8', 'text/html; charset=utf-8']}));
// CORS handled by nginx
// app.use(cors({origin: process.env.ALLOW_ORIGIN,
// allowedHeaders: ['Content-Type', 'application/json; charset=utf-8', 'text/html; charset=utf-8']}));
app.use('/v1/assets', express.static(__dirname + '/assets'));
app.post('/v1/contact', function(req, res) {
@ -37,22 +37,16 @@ app.listen(process.env.PORT || 7000, function(){
});
function sendEmail(data, res){
var email = { "from": process.env.EMAIL_FROM, "to": process.env.EMAIL_TO};
email.subject = 'MY BLOG - ' + (data.subject && data.subject.toUpperCase());
var email = {
"from": process.env.EMAIL_FROM,
"to": process.env.EMAIL_TO,
"replyTo": `${data.name} <${data.email}>`,
"subject": `tobiaseigen.org contact form message from ${data.name}`,
"text": data.message
};
const output = `
<p>Hello,<p>
<p>You got a new contact request.</p>
<h3>Contact Details</h3>
<ul><li>Name: ${data.name}</li><li>Email: ${data.email}</li></ul>
<h3>Message:</h3>
<p>${data.message}</p>
`
email.html = sanitize(output, {
allowedTags: sanitize.defaults.allowedTags.concat([ 'img' ])
});
transporter.sendMail(email, function(error, info){
if(error) return res.json({"sendEmail": "failed"});
if(error) { console.log("SMTP ERROR:", error); return res.json({"sendEmail": "failed"}); }
res.json({"sendEmail": "ok"});
});
};