z3r0Luck
4 years ago
1102 changed files with 0 additions and 60 deletions
@ -1,13 +0,0 @@ |
|||||
<!DOCTYPE html> |
|
||||
<html lang="en"> |
|
||||
<head> |
|
||||
<meta charset="UTF-8"> |
|
||||
<title>Cloud Web App</title> |
|
||||
</head> |
|
||||
<body> |
|
||||
<form action="/quotes" method="POST"> |
|
||||
<input type="text" placeholder="name" name="name"> |
|
||||
<input type="text" placeholder="post" name="post"> |
|
||||
<button type="submit">Submit</button> |
|
||||
</form> |
|
||||
</body> |
|
@ -1,47 +0,0 @@ |
|||||
|
|
||||
|
|
||||
// declaring dependencies |
|
||||
const express = require('express'); |
|
||||
const bodyParser= require('body-parser') |
|
||||
const app = express(); |
|
||||
// Make sure you place body-parser before your CRUD handlers! |
|
||||
app.use(bodyParser.urlencoded({ extended: true })) |
|
||||
|
|
||||
// Constants |
|
||||
const PORT = 8080; |
|
||||
const HOST = '0.0.0.0'; |
|
||||
|
|
||||
var MongoClient = require('mongodb').MongoClient; |
|
||||
var connectionString = "mongodb://10.0.5.3:27017/"; |
|
||||
|
|
||||
MongoClient.connect(connectionString, { useUnifiedTopology: true }) |
|
||||
.then(client => { |
|
||||
console.log('Connected to Database') |
|
||||
const db = client.db('cloudDB') |
|
||||
const quotesCollection = db.collection('mycollection') |
|
||||
|
|
||||
|
|
||||
|
|
||||
app.post('/quotes', (req, res) => { |
|
||||
quotesCollection.insertOne(req.body) |
|
||||
.then(result => { |
|
||||
res.redirect('/') |
|
||||
}) |
|
||||
.catch(error => console.error(error)) |
|
||||
}) |
|
||||
|
|
||||
app.get('/', (req, res) => { |
|
||||
const cursor = db.collection('quotes').find().toArray() |
|
||||
.then(results => { |
|
||||
console.log(results) |
|
||||
}) |
|
||||
res.sendFile(__dirname + '/index.html') |
|
||||
}) |
|
||||
|
|
||||
app.listen(PORT, HOST); |
|
||||
|
|
||||
}) |
|
||||
|
|
||||
|
|
||||
console.log(`Running on http://${HOST}:${PORT}`); |
|
||||
|
|
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue