Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. {
  2. "name": "***",
  3. "version": "0.0.0",
  4. "private": true,
  5. "scripts": {
  6. "start": "node app.js",
  7. "monitor": "nodemon app.js",
  8. "deploy": "gcloud app deploy app.yaml"
  9. },
  10. "dependencies": {
  11. "async": "^2.1.5",
  12. "body-parser": "^1.13.3",
  13. "cookie-parser": "^1.3.5",
  14. "crypto": "0.0.3",
  15. "debug": "~2.2.0",
  16. "express": "^4.13.4",
  17. "express-mysql-session": "^1.2.0",
  18. "express-session": "^1.15.1",
  19. "helmet": "^3.5.0",
  20. "moment": "^2.18.1",
  21. "morgan": "~1.6.1",
  22. "mysql": "^2.13.0",
  23. "nconf": "^0.8.4",
  24. "password-hash": "^1.2.2",
  25. "prompt": "^1.0.0",
  26. "pug": "^2.0.0-beta11",
  27. "serve-favicon": "~2.3.0",
  28. "socket.io": "^1.7.3"
  29. }
  30. }
  31.  
  32. service: default
  33. env: flex
  34. runtime: nodejs
  35. env_variables:
  36. NODE_ENV: production
  37. MYSQL_USER: ***
  38. MYSQL_PASSWORD: ***
  39. INSTANCE_CONNECTION_NAME: ***:us-central1:***
  40. beta_settings:
  41. cloud_sql_instances: ***:us-central1:***
  42.  
  43. var nconf = module.exports = require('nconf');
  44. var path = require('path');
  45.  
  46. nconf.argv().env([
  47. 'NODE_ENV',
  48. 'DATA_BACKEND',
  49. 'GCLOUD_PROJECT',
  50. 'MYSQL_USER',
  51. 'MYSQL_PASSWORD',
  52. 'INSTANCE_CONNECTION_NAME',
  53. 'PORT'
  54. ])
  55. .file({ file: path.join(__dirname, 'config.json')})
  56. .defaults({
  57. DATA_BACKEND: 'cloudsql',
  58. GCLOUD_PROJECT: '***',
  59. MYSQL_USER: '***',
  60. MYSQL_PASSWORD: '***',
  61. INSTANCE_CONNECTION_NAME: '***:us-central1:***',
  62. PORT: 8080
  63. });
  64.  
  65. checkConfig('GCLOUD_PROJECT');
  66.  
  67. if (nconf.get('DATA_BACKEND') === 'cloudsql') {
  68. checkConfig('MYSQL_USER');
  69. checkConfig('MYSQL_PASSWORD');
  70. if (nconf.get('NODE_ENV') === 'production') {
  71. checkConfig('INSTANCE_CONNECTION_NAME');
  72. }
  73. }
  74.  
  75. function checkConfig (setting) {
  76. if (!nconf.get(setting)) {
  77. throw new Error('You must set ' + setting + 'as an environment variable or in config.json!');
  78. }
  79. }
  80.  
  81. var express = require('express');
  82. var session = require('express-session');
  83. var MySQLStore = require('express-mysql-session')(session);
  84. ...
  85. var helmet = require('helmet');
  86.  
  87. var routes = require('./routes/index');
  88. ...
  89.  
  90. var app = express();
  91.  
  92. var config = require('./config');
  93. ...
  94.  
  95. var port = process.env.PORT || 8080;
  96.  
  97.  
  98. app.set('port', port);
  99. // view engine setup
  100. app.set('views', path.join(__dirname, 'views'));
  101. app.set('view engine', 'pug');
  102. app.set('trust proxy', true);
  103. // uncomment after placing your favicon in /public
  104. //app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
  105.  
  106. app.use(express.static(path.join(__dirname, 'public')));
  107.  
  108. app.use(helmet());
  109. ...
  110.  
  111. var options = {
  112. user: config.get('MYSQL_USER'),
  113. password: config.get('MYSQL_PASSWORD'),
  114. database: ''***',',
  115. checkExpirationInterval: 900000,
  116. expiration: 186400 * 365
  117. };
  118. if (config.get('NODE_ENV') === "production") {
  119. options.socketPath = '/cloudsql/' + config.get('INSTANCE_CONNECTION_NAME');
  120. } else {
  121. options.host = ''***',';
  122. }
  123.  
  124. var sessionStore = new MySQLStore(options);
  125. app.use(session({
  126. key: '***', // 세션키
  127. secret: ''***',', // 비밀키
  128. saveUninitialized: false,
  129. resave: true,
  130. store: sessionStore,
  131. cookie: {
  132. expires: new Date() + 186400 * 365,
  133. maxAge: 186400 * 365 // 쿠키 유효기간 1년
  134. }
  135. }));
  136.  
  137. app.use('/', routes);
  138. ...
  139.  
  140. // catch 404 and forward to error handler
  141. app.use(function(req, res, next) {
  142. var err = new Error('Not Found');
  143. err.status = 404;
  144. next(err);
  145. });
  146.  
  147. // error handlers
  148.  
  149. // development error handler
  150. // will print stacktrace
  151. if (app.get('env') === 'development') {
  152. app.use(function(err, req, res, next) {
  153. res.status(err.status || 500);
  154. res.render('error', {
  155. message: err.message,
  156. error: err
  157. });
  158. });
  159. }
  160.  
  161. // production error handler
  162. // no stacktraces leaked to user
  163. app.use(function(err, req, res, next) {
  164. res.status(err.status || 500);
  165. res.render('error', {
  166. message: err.message,
  167. error: {}
  168. });
  169. });
  170.  
  171. // Socket.io
  172. var server = require('http').createServer(app);
  173. var io = require('socket.io').listen(server);
  174. server.listen(3000);
  175.  
  176. io.sockets.on('connection', function(socket) {
  177. ...
  178. });
  179.  
  180. app.listen(port);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement