-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
53 lines (41 loc) · 1.21 KB
/
app.js
File metadata and controls
53 lines (41 loc) · 1.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
// app.js
// Requiring in-built https for creating
// https server
const https = require("https");
// Express for handling GET and POST request
const express = require("express");
const app = express();
// Requiring file system to use local files
const fs = require("fs");
// Parsing the form of body to take
// input from forms
const bodyParser = require("body-parser");
// Configuring express to use body-parser
// as middle-ware
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
// Get request for root of the app
app.get("/", function (req, res) {
// Sending index.html to the browser
res.sendFile(__dirname + "/index.html");
});
// Post request for geetting input from
// the form
app.post("/mssg", function (req, res) {
// Logging the form body
console.log(req.body);
// Redirecting to the root
res.redirect("/");
});
// Creating object of key and certificate
// for SSL
const options = {
key: fs.readFileSync("server.key"),
cert: fs.readFileSync("server.cert"),
};
// Creating https server by passing
// options and app object
https.createServer(options, app)
.listen(46464, function (req, res) {
console.log("Server started at port 46464");
});