-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
81 lines (66 loc) · 2.05 KB
/
index.js
File metadata and controls
81 lines (66 loc) · 2.05 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
let env = process.env.NODE_ENV || 'development';
let knex = require('knex')(require('./knexfile')[env]);
let winston = require('winston');
let fs = require('fs-extra');
let config = require('./config/config.json')[env];
require('winston-papertrail').Papertrail;
require('pretty-error').start();
import postgraphql from 'postgraphql';
import Koa from 'koa';
let app = new Koa();
// move to koa middleware
winston.configure({
transports: [
new(winston.transports.Console)({
level: 'debug',
colorize: true,
prettyPrint: true
}),
new(winston.transports.File)({
filename: 'logs/postgresIndexjs.log',
level: 'info'
})
]
});
if (env == 'production') {
winston.add(winston.transports.Papertrail, {
host: 'logs5.papertrailapp.com',
port: 47865,
level: 'debug',
colorize: true,
prettyPrint: true
});
}
app.use(
postgraphql(
`postgres:${config.USER}:${config.PASSWORD}@${config.HOST}:${config.PORT}/${config.DBNAME}`, //concat to shorten later
'public', //schema
{ graphiql: true } //options
)
);
winston.log('debug', 'PostGraphQL connection established');
// move this to middleware as well
//
//app.use(async (ctx, next) => {
//winston.log('debug', 'inside 2nd middleware');
// //eventually put this in a function and move out of index.js
// knex.migrate.latest()
// .then(function() {
// if (fs.existsSync(__dirname + `/db/seeds/${env}`)) {
// winston.log('info', `seeding ${env} db`);
// winston.log('info', 'ran migrations from index.js. DB should be up to date.');
// return knex.seed.run();
// } else {
// winston.log('info', `${env} seed directory does not exist. seeding will not occur`);
// }
// })
// .catch(function(err) {
// winston.log('debug', err);
// console.log(err);
// })
// .finally(function() {
// process.exit();
// });
//await next();
//});
app.listen(3000, () => winston.log('debug', 'server running on localhost:3000'));