-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
87 lines (68 loc) · 2.25 KB
/
app.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
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
'use strict';
var express = require('express');
var compression = require('compression');
const fs = require('fs');
var spdy = require('spdy');
var bodyParser = require('body-parser');
var oauth2 = require('./api/oauth2.js');
var account = require('./api/account.js');
var post = require('./api/post.js');
var app = express();
var router = express.Router();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(compression());
app.use("/bower_components",express.static('bower_components'));
app.use("/" ,express.static('public'));
app.use("/api/oauth2" , oauth2);
app.use("/api/account" , account);
app.use("/api/post" , post);
app.use(logErrors)
app.use(clientErrorHandler)
app.use(errorHandler)
app.listen(5051);
/*
// And go for login
Client.Session.create(device, storage, 'jk@codecraft.co.kr', 'zktmxpfk0207')
.then(function(session) {
// Now you have a session, we can follow / unfollow, anything...
// And we want to follow Instagram official profile
//return [session, Client.Account.searchForUser(session, 'instagram')]
// JPEG is the only supported format now, pull request for any other format welcomed!
/*
return Client.Upload.photo(session, 'img.jpg')
.then(function(upload) {
// upload instanceof Client.Upload
// nothing more than just keeping upload id
console.log(upload.params.uploadId);
return Client.Media.configurePhoto(session, upload.params.uploadId, 'akward caption 한글 #test');
})
})
.spread(function(session, account) {
return Client.Relationship.create(session, account.id);
})
.then(function(rtn) {
console.log(rtn)
// {followedBy: ... , following: ... }
// Yey, you just followed @instagram
})
*/
function logErrors (err, req, res, next) {
//에러 로깅... 필요하나?
//console.error(err.stack)
next(err)
}
function clientErrorHandler (err, req, res, next) {
if (req.xhr) {
res.status((!err.output)?500:err.output.statusCode).send({ error: err.message , data : err.data})
} else {
next(err)
}
}
function errorHandler (err, req, res, next) {
if (res.headersSent) {
return next(err)
}
res.status((!err.output)?500:err.output.statusCode)
res.send( { message : err.message , data : err.data })
}