-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
107 lines (89 loc) · 3.21 KB
/
app.js
File metadata and controls
107 lines (89 loc) · 3.21 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* Ocean-Minded Application Script
*
* Copyright © Vladislav Kazantsev
* All rights reserved.
* This code is the intellectual property of Vladislav Kazantsev.
* You are welcome to clone the related repository and use the code for exploratory purposes.
* However, unauthorized reproduction, modification, or redistribution of this code (including cloning of related repository or altering it for activities beyond exploratory use) is strictly prohibited.
* Code snippets may be shared only when the original author is explicitly credited and a direct link to the original source of the code is provided alongside the code snippet.
* Sharing the link to the file is permitted, except when directed toward retrieval purposes.
* Any form of interaction with this file is strictly prohibited when facilitated by the code, except when such interaction is for discussion or exchange purposes with others.
* This copyright notice applies globally.
* For inquiries about collaboration, usage outside exploratory purposes, or permissions, please contact: hypervisor7@pm.me
*/
import express from "express";
import path from "path";
import fs from "fs";
import { fileURLToPath } from "url";
import pkg from "twig";
const app = express();
const port = 3000;
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const { twig } = pkg;
app.set("view engine", "ejs");
app.set("views", path.join(__dirname, "views"));
// Serve static files
app.use(express.static("public"));
// Middleware to parse JSON bodies
app.use(express.json());
// Home page route
app.get("/", (req, res) => {
const brandTitlePath = path.join(
__dirname,
"views",
"partials",
"brand-title.twig"
);
const brandTitle = fs.readFileSync(brandTitlePath, "utf8");
const rendered = twig({ data: brandTitle }).render({
title: "Ocean-Minded",
subtitle: "Your Way to Beautiful Journeys",
imageClass: "logo img-fluid",
imageSrc: "images/logo.jpg",
imageAlt: "The Ocean-Minded Logo Image",
});
res.render("index.ejs", { brandTitle: rendered });
});
// About page route
app.get("/about", (req, res) => {
res.render("about.ejs");
});
// Services page route
app.get("/services", (req, res) => {
res.render("services.ejs");
});
// Team page route
app.get("/team", (req, res) => {
res.render("team.ejs");
});
// Contact page route
app.get("/contact", (req, res) => {
res.render("contact.ejs");
});
// Caribbean Beauty page route
app.get("/destinations/caribbean", (req, res) => {
res.render("destinations/caribbean.ejs");
});
// Pacific Northwest page route
app.get("/destinations/pacific-northwest", (req, res) => {
res.render("destinations/pacific-northwest.ejs");
});
// Mediterranean Sea page route
app.get("/destinations/mediterranean", (req, res) => {
res.render("destinations/mediterranean.ejs");
});
// Hawaii page route
app.get("/destinations/hawaii", (req, res) => {
res.render("destinations/hawaii.ejs");
});
// Subscription route
app.post("/subscribe", (req, res) => {
const { email } = req.body;
console.log(`New subscription: ${email}`);
res.status(200).send("Subscription successful");
});
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});