This repository has been archived by the owner on Nov 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathserver.js
executable file
·53 lines (45 loc) · 1.91 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
51
52
53
console.log("process.env.TOKEN", process.env.TOKEN);
console.log("process.env.NAME", process.env.NAME);
process.env.NODE_ENV_COZYHACK = "development"
var ghost = require('./server/ghost/core/index');
var path = require('path');
var importer = require(path.join(__dirname,'./server/ghost/core/server/data/importer/index'));
var cozydb = require('cozydb');
var Blog = require('./server/models/blog');
var CozyInstance = require('./server/models/instance');
var models = require(path.join(__dirname,'./server/ghost/core/server/models/index'));
var saveListener = require('./server/ghost_hacking/save_listener');
var initial_datum = require('./server/ghost_hacking/initial_datum');
var ghostConfig = require('./server/ghost/config.js');
cozydb.configure(__dirname, null, function(){
CozyInstance.getDomain(function(err, domain){
if(err) {
console.log(err)
return
}
console.log("domain : ", domain);
domain = "http://" + domain;
// ghostConfig.production.url = require('url').resolve(domain, '/public/blog/');
ghostConfig.development.url = require('url').resolve(domain, '/public/blog/');
ghost().then(function(ghostServer) {
console.log("ghost.then()");
models.deleteAllContent().then(function(){ //delete old blog post to avoid duplicate entries
Blog.request("all", {}, function(err, blog) {
if(err !== null) {
console.log(err);
} else {
if (blog.length > 0) {
console.log("importing...");
importer.doImport.bind(importer)({data : blog[0].content.db[0]});
console.log("importing...done");
}else {
importer.doImport.bind(importer)({data : initial_datum.db[0]});
}
setTimeout(saveListener.activate ,60*1000); //no need to persist the first op
return ghostServer.start();
}
});
});
});
});
});