You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.8 KiB
65 lines
1.8 KiB
var createError = require('http-errors');
|
|
const mongoose = require('mongoose');
|
|
var express = require('express');
|
|
var path = require('path');
|
|
bodyParser = require('body-parser');
|
|
var app = express();
|
|
app.use(bodyParser.json());
|
|
app.use(bodyParser.urlencoded({ extended: true }));
|
|
port = process.env.PORT || 3500;
|
|
app.listen(port);
|
|
console.log('Server started on: ' + port);
|
|
|
|
app.get('/', (req, res) => {
|
|
res.send('Hello World!')
|
|
})
|
|
|
|
app.get('/home', (req, res) => {
|
|
res.send('Hello Home!')
|
|
})
|
|
|
|
main().catch(err => console.log(err));
|
|
|
|
async function main() {
|
|
mongoose.connect('mongodb://localhost:27017/ekam').then(() => {
|
|
console.log('mongodb connected');
|
|
});
|
|
}
|
|
|
|
var conn = mongoose.connection;
|
|
|
|
conn.on('connected', function () {
|
|
console.log('database is connected successfully');
|
|
});
|
|
|
|
conn.on('disconnected',function(){
|
|
console.log('database is disconnected successfully');
|
|
});
|
|
|
|
conn.once('open', function () {
|
|
console.log('connection open successfully');
|
|
});
|
|
|
|
// Add headers
|
|
app.use(function (req, res, next) {
|
|
// Website you wish to allow to connect
|
|
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
// Request methods you wish to allow
|
|
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
|
|
// Request headers you wish to allow
|
|
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
|
|
// Set to true if you need the website to include cookies in the requests sent
|
|
// to the API (e.g. in case you use sessions)
|
|
res.setHeader('Access-Control-Allow-Credentials', true);
|
|
// Pass to next layer of middleware
|
|
next();
|
|
});
|
|
|
|
app.get('/scheduleAppointmentAPI', (req, res) => {
|
|
const collections = conn.db.collection("ahc");
|
|
collections.find({}).toArray(function (err, data) {
|
|
res.send(data);
|
|
})
|
|
});
|
|
|
|
|