This repository has been archived by the owner on Dec 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (37 loc) · 1.4 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
const express = require('express')
const bodyParser = require('body-parser')
const methodOverride = require('method-override')
const mongoose = require('mongoose')
const restify = require('express-restify-mongoose')
const app = express()
const router = express.Router()
const cors = require('cors')
app.use(bodyParser.json())
app.use(methodOverride())
app.use(cors())
// When successfully connected
mongoose.connection.on('connected', function () {
console.log('Mongoose default connection open!');
});
// If the connection throws an error
mongoose.connection.on('error',function (err) {
console.log('Mongoose default connection error!');
});
console.log(process.env.MONGODB_URI)
mongoose.connect(process.env.MONGODB_URI)
var Schema=mongoose.Schema
restify.serve(router, mongoose.model('Page', new mongoose.Schema({
isFirst: {type: Boolean, required: true},
pageText: { type: String, required: true }, // Top TWO lines should be the story title and info
Link1: { type: Schema.Types.ObjectId, ref: 'Page' },
Link2: { type: Schema.Types.ObjectId, ref: 'Page' },
Link3: { type: Schema.Types.ObjectId, ref: 'Page' },
Link4: { type: Schema.Types.ObjectId, ref: 'Page' },
storyHead: { type: Schema.Types.ObjectId, ref: 'Page' },
backlink: { type: Schema.Types.ObjectId, ref: 'Page' }
})))
app.use(router)
let port= 3001;
app.listen(port, () => {
console.log(`Express server listening on port ${port}`)
})