2019-09-12 06:23:03 +02:00
|
|
|
const express = require("express");
|
2019-01-12 14:09:17 +01:00
|
|
|
const path = require("path");
|
|
|
|
|
const bodyParser = require("body-parser");
|
2019-09-04 07:00:27 -07:00
|
|
|
const layout = require("express-layout");
|
2019-09-12 06:23:03 +02:00
|
|
|
const compression = require("compression");
|
2019-10-16 12:49:58 +02:00
|
|
|
const forceSSL = require("./app/helpers/forceSSL");
|
2019-09-12 06:23:03 +02:00
|
|
|
|
2020-02-13 17:08:49 +01:00
|
|
|
const { Storage } = require("@google-cloud/storage");
|
2020-02-12 11:44:56 +01:00
|
|
|
const validate = require("validate.js");
|
|
|
|
|
|
2019-09-26 23:55:34 +02:00
|
|
|
const {
|
|
|
|
|
APP_PORT,
|
|
|
|
|
CRAWLER_INTERVAL,
|
2020-01-24 16:04:28 +01:00
|
|
|
STOP_CRAWLER
|
2019-09-26 23:55:34 +02:00
|
|
|
} = require("./app/config/appConfig");
|
2019-09-12 06:23:03 +02:00
|
|
|
const routes = require("./app/routes");
|
2019-09-26 17:30:06 +02:00
|
|
|
const { crawlAll } = require("./app/crawler/crawl");
|
2020-01-24 01:01:10 +01:00
|
|
|
const { checkUpNotify } = require("./app/services/notificationService");
|
2019-09-30 13:53:35 +02:00
|
|
|
const {
|
|
|
|
|
notifyForNewRealEstates
|
|
|
|
|
} = require("./app/services/notificationService");
|
2019-01-12 14:09:17 +01:00
|
|
|
|
|
|
|
|
const app = express();
|
2019-09-12 06:23:03 +02:00
|
|
|
|
2019-10-16 12:49:58 +02:00
|
|
|
app.use(forceSSL());
|
2019-01-19 16:53:27 +01:00
|
|
|
app.use(bodyParser.json());
|
|
|
|
|
app.use(bodyParser.urlencoded({ extended: true }));
|
2019-01-19 19:20:21 +01:00
|
|
|
|
2019-09-04 07:00:27 -07:00
|
|
|
app.set("views", path.join(__dirname, "/app/views"));
|
|
|
|
|
app.set("view engine", "ejs");
|
2019-04-09 06:01:21 +02:00
|
|
|
app.use(layout());
|
2019-03-26 05:09:53 +01:00
|
|
|
|
2019-04-13 10:38:25 +02:00
|
|
|
app.use(compression());
|
2019-09-12 06:23:03 +02:00
|
|
|
app.use("/", routes);
|
2019-09-04 07:00:27 -07:00
|
|
|
|
|
|
|
|
app.use("/assets", express.static("./app/public"));
|
2019-03-13 05:43:48 +01:00
|
|
|
|
2019-09-05 14:24:29 +02:00
|
|
|
app.listen(APP_PORT, () =>
|
|
|
|
|
console.log(`Example app listening on port ${APP_PORT}!`)
|
|
|
|
|
);
|
2019-09-26 17:30:06 +02:00
|
|
|
|
2019-09-26 23:55:34 +02:00
|
|
|
let crawlerRunning = STOP_CRAWLER;
|
2019-09-26 17:30:06 +02:00
|
|
|
const crawl = () => {
|
|
|
|
|
if (!crawlerRunning) {
|
|
|
|
|
crawlerRunning = true;
|
|
|
|
|
crawlAll().then(newRealEstates => {
|
|
|
|
|
crawlerRunning = false;
|
2019-09-30 13:53:35 +02:00
|
|
|
notifyForNewRealEstates(newRealEstates);
|
2019-09-26 17:30:06 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
2020-01-24 01:01:10 +01:00
|
|
|
|
2019-09-26 17:30:06 +02:00
|
|
|
setInterval(crawl, CRAWLER_INTERVAL * 1000);
|
2020-01-24 01:01:10 +01:00
|
|
|
|
2020-01-24 16:04:28 +01:00
|
|
|
setInterval(checkUpNotify, 1000 * 60 * 60 * 24);
|
2020-02-13 17:08:49 +01:00
|
|
|
|
|
|
|
|
//Google storage req
|
|
|
|
|
const storage = new Storage();
|
|
|
|
|
|
|
|
|
|
storage
|
|
|
|
|
.getBuckets()
|
|
|
|
|
.then(results => {
|
|
|
|
|
const buckets = results[0];
|
|
|
|
|
|
|
|
|
|
console.log("Buckets:");
|
|
|
|
|
buckets.forEach(bucket => {
|
|
|
|
|
console.log(bucket.name);
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
console.error("GOOGLE ERROR:", err);
|
|
|
|
|
});
|
|
|
|
|
/*
|
|
|
|
|
bucket = gcs.bucket('aBucket')
|
|
|
|
|
bucket.file('aFile').getSignedUrl({
|
|
|
|
|
action: 'write',
|
|
|
|
|
expires: moment.utc().add(1, 'days').format(),
|
|
|
|
|
}, (error, signedUrl) => {
|
|
|
|
|
if (error == null) {
|
|
|
|
|
console.log(`Signed URL is ${signedUrl}`)
|
|
|
|
|
}
|
|
|
|
|
}) */
|