-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
68 lines (54 loc) · 1.87 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import express from "express";
import bodyParser from "body-parser";
import { dirname } from 'path';
import { fileURLToPath } from 'url';
import path from 'path';
import dotenv from 'dotenv';
dotenv.config();
const app = express();
const port = process.env.PORT || 3000;
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
app.set('view engine', 'ejs');
app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static("public"));
app.use('/public', express.static('public'));
app.get("/", (req, res) => {
res.render(path.join(__dirname,'views', 'index.ejs'));
});
app.get("/connect", (req, res) => {
res.render(path.join(__dirname,'views', 'connect.ejs'));
});
app.get("/achievement", (req, res) => {
res.render(path.join(__dirname,'views', 'achievement.ejs'));
});
app.get("/projects", (req, res) => {
res.render(path.join(__dirname,'views', 'projects.ejs'));
});
app.get("/education", (req, res) => {
res.render(path.join(__dirname,'views', 'education.ejs'));
});
app.get("/header", (req, res) => {
res.render(path.join(__dirname,'views','partials', 'header.ejs'));
});
app.get("/footer", (req, res) => {
res.render(path.join(__dirname,'views','partials', 'footer.ejs'));
});
app.post('/submit', (req, res) => {
// Handle the form submission here
const { name, email, message } = req.body;
// Process the form data, e.g., save to the database or send an email
// Respond with a success message (JSON or HTML depending on your needs)
res.json({ message: 'Form submitted successfully' });
});
app.get('/contact', (req, res) => {
res.render('contact', {
WebappURL: process.env.WebappURL
});
});
// Start the server
app.listen(process.env.PORT || 3000, () => {
console.log(`Server is running on http://localhost:${port}`);
});