-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
116 lines (88 loc) · 2.8 KB
/
server.js
File metadata and controls
116 lines (88 loc) · 2.8 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
const express = require('express');
const bodyParser = require('body-parser')
require('dotenv').config();
const app = express();
const cookieParser = require("cookie-parser");
const PORT = process.env.PORT || 8081;
require('./cron/crone.js');
// require('./database/connection.js');
const cors = require('cors');
const whitelist = ['http://127.0.0.1'];
const fakery = require('mongoose-fakery');
const mail = require('./mail/mail.js')
global.__basedir = __dirname;
// const corsOptions = {
// origin: (origin, callback) => {
// if (whitelist.indexOf(origin) !== -1) {
// callback(null, true)
// } else {
// callback(new Error())
// }
// }
// }
// const corsOptions = {
// origin: ['https://www.section.io', 'https://www.google.com/']
// }
app.use(cors());
// Make sure you place body-parser before your CRUD handlers!
app.use(bodyParser.urlencoded({ extended: true }))
// to accept json row data request
app.use(express.json())
app.use(cookieParser());
if (process.env.NODE_ENV !== 'test') {
app.listen(PORT, function () {
console.log('listening on ' + PORT);
});
}
else {
console.log('APP IS ON DEVELOPMENT ENVIRONMENT');
}
const routes = require('./routes/api.js');
// const {connection} = require("./database/connection.js");
const Category = require('./models/Category.js');
const User = require('./models/User.js');
// fakery.fake('category',connection.model('Category'), {
// name: fakery.g.name()
// });
// fakery.fake('user',connection.model('User'), {
// firstName: fakery.g.name(),
// lastName: fakery.g.name(),
// password: fakery.g.name(),
// username: fakery.g.name(),
// city: fakery.g.name()
// });
// for (let i = 0; i < 10; i++) {
// // const category = fakery.fake('category');
// // new Category(category).save()
// // const user = fakery.fake('user');
// // new User(user).save()
// }
app.use('/', routes);
// async function fetchAll() {
// // const res = fetch(`https://jsonplaceholder.typicode.com/posts/1`);
// const length = 20;
// const ids = Array.from(Array(length).keys()); // Array of ids
// // const responses = Promise.all(
// // ids.map(async id => {
// // fetch(
// // `http://127.0.0.1:8000/api/product-custom?session_id=${id}`
// // ); // Send request for each id
// // })
// // );
// let endpoints = [];
// const url = "http://127.0.0.1:8000/api/product-custom?session_id=";
// ids.forEach((item)=>{
// endpoints.push(url+item);
// })
// axios.all(endpoints.map((endpoint) => axios.get(endpoint))).then(
// (data) => console.log(data),
// );
// // console.log(responses);
// }
// setInterval(() => {
// fetchAll();
// }, 20000);
// setInterval(() => {
// fetchAll();
// }, 7000);
module.exports = app;