Skip to content

Commit

Permalink
node backend
Browse files Browse the repository at this point in the history
  • Loading branch information
1BlauNitrox committed Mar 10, 2024
1 parent d2acc73 commit c3203f0
Show file tree
Hide file tree
Showing 1,719 changed files with 297,753 additions and 27,022 deletions.
36 changes: 36 additions & 0 deletions api/form-validation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// api/form-validation.js

const express = require('express');
const { Resend } = require('resend');

const router = express.Router();

router.post('/', async (req, res) => {
const { name, email, content } = req.body;

// Initialize Resend client
const resend = new Resend(process.env.EMAIL_KEY);

try {
// Send email using Resend
const { data, error } = await resend.emails.send({
from: 'Acme <[email protected]>',
to: ['[email protected]'],
subject: 'Hello World',
html: '<strong>It works!</strong>',
});

if (error) {
console.error({ error });
return res.status(500).json({ error: 'Failed to send email' });
}

console.log({ data });
res.status(200).json({ message: 'Email sent successfully' });
} catch (error) {
console.error(error);
res.status(500).json({ error: 'Internal server error' });
}
});

module.exports = router;
26 changes: 0 additions & 26 deletions api/form-validation.php

This file was deleted.

2 changes: 0 additions & 2 deletions api/index.php

This file was deleted.

25 changes: 25 additions & 0 deletions api/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// api/server.js

const express = require('express');
const bodyParser = require('body-parser');
const formValidationRouter = require('./form-validation');

const app = express();
const PORT = process.env.PORT || 3000;

// Middleware
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

// Routes
app.use('/api/form-validation', formValidationRouter);

// Serve the index.html file for the root URL
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, '..', 'index.html'));
});

// Start server
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
5 changes: 0 additions & 5 deletions composer.json

This file was deleted.

Loading

0 comments on commit c3203f0

Please sign in to comment.