-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
50 lines (44 loc) · 1.67 KB
/
server.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
const express = require('express');
var bodyParser = require('body-parser');
const app = express();
const port = process.env.PORT || 5000;
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
/////////////////////////////////////MONGOOSE START///////////////////////////////////
const mongoose = require('mongoose');
mongoose.connect('mongodb://drawit:[email protected]:47101/drawit');
var db = mongoose.connection;
db.on('error', console.error.bind(console, '//////////////////////connection error//////////////////////'));
db.once('open', function() {
console.log("////////////////////Connected To MongoLab Cloud Database////////////////////");
});
/////SCHEMA////
var productSchema = mongoose.Schema(
{
id : String,
courseName : String,
info : String,
author : String,
learn: [],
videos : [],
includes : [],
});
var product = mongoose.model('product',productSchema);
/////////////////////////////////////MONGOOSE END///////////////////////////////////
const path = require('path');
app.use(express.static(path.join(__dirname, 'client/build')));
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname+'/client/build/index.html'));
});
//////////////////////////////////RETERIVING SAVED PAGES ///////////////////////////////////
app.get('/find/:key',function(req,res){
var key = req.params.key;
Url.findOne({id:key},function (err, code)
{
if (err) return console.error("eError");
console.log('code');
res.send(code);
});
});
////////////////////////////RETERIVING SAVED PAGES END ////////////////////////////////
app.listen(port, () => console.log(`Listening on port ${port}`));