File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 1+ const express = require ( 'express' ) ;
2+ const bodyParser = require ( 'body-parser' ) ;
3+ const app = express ( ) ;
4+ const port = 3000 ;
5+
6+ // Middleware
7+ app . use ( bodyParser . json ( ) ) ;
8+ app . use ( express . static ( 'public' ) ) ;
9+
10+ // Endpoints
11+ app . get ( '/' , ( req , res ) => {
12+ res . sendFile ( __dirname + '/public/index.html' ) ;
13+ } ) ;
14+
15+ app . post ( '/api/contact' , ( req , res ) => {
16+ const { name, email, message } = req . body ;
17+ console . log ( `Received contact form submission:
18+ Name: ${ name }
19+ Email: ${ email }
20+ Message: ${ message } ` ) ;
21+ res . json ( { status : 'success' , message : 'Form submitted successfully' } ) ;
22+ } ) ;
23+
24+ // Start the server
25+ app . listen ( port , ( ) => {
26+ console . log ( `Server is running at http://localhost:${ port } ` ) ;
27+ } ) ;
You can’t perform that action at this time.
0 commit comments