Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "name": "***",
- "version": "0.0.0",
- "private": true,
- "scripts": {
- "start": "node app.js",
- "monitor": "nodemon app.js",
- "deploy": "gcloud app deploy app.yaml"
- },
- "dependencies": {
- "async": "^2.1.5",
- "body-parser": "^1.13.3",
- "cookie-parser": "^1.3.5",
- "crypto": "0.0.3",
- "debug": "~2.2.0",
- "express": "^4.13.4",
- "express-mysql-session": "^1.2.0",
- "express-session": "^1.15.1",
- "helmet": "^3.5.0",
- "moment": "^2.18.1",
- "morgan": "~1.6.1",
- "mysql": "^2.13.0",
- "nconf": "^0.8.4",
- "password-hash": "^1.2.2",
- "prompt": "^1.0.0",
- "pug": "^2.0.0-beta11",
- "serve-favicon": "~2.3.0",
- "socket.io": "^1.7.3"
- }
- }
- service: default
- env: flex
- runtime: nodejs
- env_variables:
- NODE_ENV: production
- MYSQL_USER: ***
- MYSQL_PASSWORD: ***
- INSTANCE_CONNECTION_NAME: ***:us-central1:***
- beta_settings:
- cloud_sql_instances: ***:us-central1:***
- var nconf = module.exports = require('nconf');
- var path = require('path');
- nconf.argv().env([
- 'NODE_ENV',
- 'DATA_BACKEND',
- 'GCLOUD_PROJECT',
- 'MYSQL_USER',
- 'MYSQL_PASSWORD',
- 'INSTANCE_CONNECTION_NAME',
- 'PORT'
- ])
- .file({ file: path.join(__dirname, 'config.json')})
- .defaults({
- DATA_BACKEND: 'cloudsql',
- GCLOUD_PROJECT: '***',
- MYSQL_USER: '***',
- MYSQL_PASSWORD: '***',
- INSTANCE_CONNECTION_NAME: '***:us-central1:***',
- PORT: 8080
- });
- checkConfig('GCLOUD_PROJECT');
- if (nconf.get('DATA_BACKEND') === 'cloudsql') {
- checkConfig('MYSQL_USER');
- checkConfig('MYSQL_PASSWORD');
- if (nconf.get('NODE_ENV') === 'production') {
- checkConfig('INSTANCE_CONNECTION_NAME');
- }
- }
- function checkConfig (setting) {
- if (!nconf.get(setting)) {
- throw new Error('You must set ' + setting + 'as an environment variable or in config.json!');
- }
- }
- var express = require('express');
- var session = require('express-session');
- var MySQLStore = require('express-mysql-session')(session);
- ...
- var helmet = require('helmet');
- var routes = require('./routes/index');
- ...
- var app = express();
- var config = require('./config');
- ...
- var port = process.env.PORT || 8080;
- app.set('port', port);
- // view engine setup
- app.set('views', path.join(__dirname, 'views'));
- app.set('view engine', 'pug');
- app.set('trust proxy', true);
- // uncomment after placing your favicon in /public
- //app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
- app.use(express.static(path.join(__dirname, 'public')));
- app.use(helmet());
- ...
- var options = {
- user: config.get('MYSQL_USER'),
- password: config.get('MYSQL_PASSWORD'),
- database: ''***',',
- checkExpirationInterval: 900000,
- expiration: 186400 * 365
- };
- if (config.get('NODE_ENV') === "production") {
- options.socketPath = '/cloudsql/' + config.get('INSTANCE_CONNECTION_NAME');
- } else {
- options.host = ''***',';
- }
- var sessionStore = new MySQLStore(options);
- app.use(session({
- key: '***', // 세션키
- secret: ''***',', // 비밀키
- saveUninitialized: false,
- resave: true,
- store: sessionStore,
- cookie: {
- expires: new Date() + 186400 * 365,
- maxAge: 186400 * 365 // 쿠키 유효기간 1년
- }
- }));
- app.use('/', routes);
- ...
- // catch 404 and forward to error handler
- app.use(function(req, res, next) {
- var err = new Error('Not Found');
- err.status = 404;
- next(err);
- });
- // error handlers
- // development error handler
- // will print stacktrace
- if (app.get('env') === 'development') {
- app.use(function(err, req, res, next) {
- res.status(err.status || 500);
- res.render('error', {
- message: err.message,
- error: err
- });
- });
- }
- // production error handler
- // no stacktraces leaked to user
- app.use(function(err, req, res, next) {
- res.status(err.status || 500);
- res.render('error', {
- message: err.message,
- error: {}
- });
- });
- // Socket.io
- var server = require('http').createServer(app);
- var io = require('socket.io').listen(server);
- server.listen(3000);
- io.sockets.on('connection', function(socket) {
- ...
- });
- app.listen(port);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement