forked from Aryamanz29/Web-Ideas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Aryamanz29#70 from abhinavdixit2306/master
NewsLetter-Signup
- Loading branch information
Showing
10 changed files
with
943 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: node app.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
//jshint esversion:6 | ||
|
||
const express = require("express"); | ||
|
||
const https = require("https"); | ||
|
||
const bodyParser = require("body-parser"); | ||
|
||
const request = require("request"); | ||
|
||
const app = express(); | ||
app.use(express.static("public")); | ||
app.use(bodyParser.urlencoded({extended:true})); | ||
//To use static files in server make folder public | ||
app.get("/", function(req,res){ | ||
res.sendFile(__dirname + "/signup.html"); | ||
}); | ||
|
||
app.post("/", function(req,res){ | ||
const fName = req.body.firstName; | ||
const lName = req.body.lastName; | ||
const email = req.body.email; | ||
|
||
const data = { | ||
|
||
members : [ | ||
{ | ||
email_address : email, | ||
status : "subscribed", | ||
merge_fields: { | ||
FNAME : fName, | ||
LNAME : lName | ||
} | ||
|
||
|
||
|
||
} | ||
] | ||
}; | ||
|
||
const jsonData = JSON.stringify(data); | ||
|
||
const url = "https://us19.api.mailchimp.com/3.0/lists/dd914356a0"; | ||
const options = { | ||
method: "POST", | ||
auth: "abhinav:974eae1ad8cf0f603ee368e6565815a7-us19" | ||
} | ||
|
||
const request = https.request(url, options, function(response){ | ||
|
||
if(response.statusCode === 200){ | ||
res.sendFile(__dirname + "/success.html"); | ||
}else{ | ||
res.sendFile(__dirname + "/failure.html"); | ||
} | ||
|
||
|
||
|
||
response.on("data", function(data){ | ||
console.log(JSON.parse(data)); | ||
|
||
}) | ||
|
||
|
||
}); | ||
|
||
request.write(jsonData); | ||
request.end(); | ||
|
||
}); | ||
|
||
app.post("/failure", function(req,res){ | ||
res.redirect("/"); | ||
}) | ||
|
||
app.listen(process.env.PORT || 3000, function(){ | ||
console.log("Server is running on port 3000"); | ||
}); | ||
|
||
|
||
|
||
//api Key | ||
//974eae1ad8cf0f603ee368e6565815a7-us19 | ||
|
||
//list id | ||
//dd914356a0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Failure</title> | ||
|
||
<!-- Bootstrap core CSS --> | ||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous"> | ||
</head> | ||
<body style="background-color: #151719;"> | ||
<div class="jumbotron jumbotron-fluid"> | ||
<div class="container"> | ||
<h1 class="display-4">Uh oh!</h1> | ||
<p class="lead">There is an error, please try again...</p> | ||
<form action="/failure" method="post"> | ||
<button class="btn btn-lg btn-warning" type="submit">Try Again</button> | ||
</form> | ||
|
||
</div> | ||
</div> | ||
</body> | ||
</html> |
Oops, something went wrong.