-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (40 loc) · 1.16 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
// add the dependencies
const express = require("express");
const path = require("path");
const bodyParser = require("body-parser");
//Export Google Sheets API config file
const Gsheet = require("./config/sheet");
// init the app
const app = express();
// allow cors
app.use(require("cors")());
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept");
next();
});
// init body parser
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// Apply ejs as the view engine and public directory for assets
app.set("view engine", "ejs");
app.use(express.static("public"));
//Added for testing
app.get('/', (req, res) => {
res.render('home.ejs');
})
app.post("/register", (req, res) => {
res.send("Request Recieved");
//Adding the row to the sheet
Gsheet.createRow(req.body, (err, row) => {
if (!err) res.sendStatus(200);
});
});
// make the port dynamically set
const PORT = process.env.PORT || 4000;
// listen to the port
app.listen(PORT, () => {
console.log(`app is listining on port ${PORT}`);
});