Skip to content
This repository has been archived by the owner on Aug 28, 2021. It is now read-only.

Commit

Permalink
scaffolded .env-base file and now relying on process.env instead of t…
Browse files Browse the repository at this point in the history
…he old CONFIG
  • Loading branch information
didimitrie committed Jun 10, 2018
1 parent 525aa3b commit 3c208a2
Show file tree
Hide file tree
Showing 16 changed files with 618 additions and 843 deletions.
43 changes: 43 additions & 0 deletions .env-base
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This is a base file for configuring the speckle server. Steps:
# 2. Copy it to .env ( `cp .env-base .env`)
# 2. Configure the .env file with your settings.
# 3. Start the speckle server!
#
# NOTE: If these are set through a different process, eg docker, pm2, or command line
# they will not be overwritten.

# SERVER_NAME: The server name is important, as it will help users differentiate
# between multiple accounts.
SERVER_NAME="Default Server"


# PORT: The port you want the speckle server to run on. Make sure the port is accesible
# if you have any firewalls set up (ie, ufw).
PORT=3000

# MAX_PROC: The maximum amount of service workers to start. If this is not specified,
# Speckle will fork out as many as the machine's processor cores. To specify it,
# just uncomment the line below.
# MAX_PROC=2

# REQ_SIZE: The request size protects your server from being flooded with too much data.
REQ_SIZE=10mb

# This is used in the encryption of the api access tokens.
# Please change it to something random!
SESSION_SECRET="helloworld"

# DBs
# Mongodb URI: this is the uri string that the server will use to connect to your mongo instance.
# The default string below will work with an out-of-the-box local mongodb deployment.
# For more info, see: https://docs.mongodb.com/manual/reference/connection-string/
MONGODB_URI="mongodb://localhost:27017/speckle"

# Redis URI: this is the uri string that the server will use to connect to your redis instance.
# The default string should work with an out-of-the-box local redis deployment.
# For more info, see http://www.iana.org/assignments/uri-schemes/prov/redis
REDIS_URL="redis://localhost:6379"

# If you want your api calls to return pretty json, set this to true. It will cause
# the reponses to be ±10% bigger.
INDENT_RESPONSES=false
3 changes: 2 additions & 1 deletion app/api/v0/accounts/UserCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const uuid = require( 'uuid/v4' )
const jwt = require( 'jsonwebtoken' )

const User = require( '../../../../models/User' )
const sessionSecret = require( '../../../../config' ).sessionSecret

module.exports = function( req, res ) {
winston.debug( 'register new user route' )
Expand All @@ -20,6 +19,8 @@ module.exports = function( req, res ) {
surname: req.body.surname ? req.body.surname : '',
apitoken: null
} )

let sessionSecret = process.env.SESSION_SECRET

User.findOne( { 'email': req.body.email } )
.then( user => {
Expand Down
3 changes: 2 additions & 1 deletion app/api/v0/accounts/UserLogin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ const chalk = require('chalk')
const jwt = require('jsonwebtoken')

const User = require('../../../../models/User')
const sessionSecret = require('../../../../config').sessionSecret

module.exports = function( req, res ) {
if( !req.body.email ) return res.send( { success: false, message:'Do not fuck with us'} )
if( !req.body.password ) return res.send( { success: false, message:'Do not fuck with us'} )

let sessionSecret = process.env.SESSION_SECRET

User.findOne( { 'email': req.body.email.toLowerCase() } )
.then( myUser => {
if( !myUser ) throw 'Invalid credentials.'
Expand Down
8 changes: 6 additions & 2 deletions app/api/v0/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ const winston = require( 'winston' )
const chalk = require( 'chalk' )
const passport = require( 'passport' )

var tokenCheck = require( './middleware/TokenCheck' )
var serverDescription = require( '../../../config' ).serverDescription
const tokenCheck = require( './middleware/TokenCheck' )

module.exports = function( app, express, urlRoot ) {
var r = new express.Router( )
Expand Down Expand Up @@ -112,6 +111,11 @@ module.exports = function( app, express, urlRoot ) {
routes.push( Object.keys( middleware.route.methods ).map( m => m.toUpperCase( ) ) + ': /api' + middleware.route.path )
} )

let serverDescription = {
serverName: process.env.SERVER_NAME,
maxRequestSize: process.env.REQ_SIZE
}

r.get( '/', ( req, res ) => {
serverDescription.routes = routes
serverDescription.version = '0.x.x'
Expand Down
3 changes: 2 additions & 1 deletion app/api/v1/accounts/UserCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const chalk = require( 'chalk' )
const jwt = require( 'jsonwebtoken' )

const User = require( '../../../../models/User' )
const sessionSecret = require( '../../../../config' ).sessionSecret

module.exports = function( req, res ) {
winston.debug( 'register new user route' )
Expand All @@ -18,6 +17,8 @@ module.exports = function( req, res ) {
surname: req.body.surname ? req.body.surname : '',
apitoken: null
} )

let sessionSecret = process.env.SESSION_SECRET

User.findOne( { 'email': req.body.email } )
.then( user => {
Expand Down
3 changes: 2 additions & 1 deletion app/api/v1/accounts/UserLogin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ const chalk = require( 'chalk' )
const jwt = require( 'jsonwebtoken' )

const User = require( '../../../../models/User' )
const sessionSecret = require( '../../../../config' ).sessionSecret

module.exports = function( req, res ) {
if ( !req.body.email ) return res.send( { success: false, message: 'Do not fuck with us' } )
if ( !req.body.password ) return res.send( { success: false, message: 'Do not fuck with us' } )

let sessionSecret = process.env.SESSION_SECRET

User.findOne( { 'email': req.body.email.toLowerCase( ) } )
.then( myUser => {
if ( !myUser ) throw 'Invalid credentials.'
Expand Down
26 changes: 15 additions & 11 deletions app/api/v1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ const winston = require( 'winston' )
const chalk = require( 'chalk' )
const passport = require( 'passport' )

var tokenCheck = require( './middleware/TokenCheck' )
var serverDescription = require( '../../../config' ).serverDescription
const tokenCheck = require( './middleware/TokenCheck' )

module.exports = function( app, express, urlRoot ) {
var r = new express.Router( )
Expand Down Expand Up @@ -102,33 +101,33 @@ module.exports = function( app, express, urlRoot ) {

// update one properties xxx
r.put( '/objects/:objectId/properties/', mandatoryAuthorisation, require( './objects/ObjectPutProperties' ) )

// delete one / perm check 'delete' xxx
r.delete( '/objects/:objectId', mandatoryAuthorisation, require( './objects/ObjectDelete' ) )


//
// COMMENTS
//

// get user's comments
r.get( '/comments', mandatoryAuthorisation, require( './comments/CommentGetAll' ) )

// get user's assignedTo comments
r.get( '/comments/assigned', mandatoryAuthorisation, require( './comments/CommentGetAssigned' ) )

// create a comment attached to a resource xxx
r.post( '/comments/:resourceType/:resourceId', optionalAuthorisation, require( './comments/CommentPost' ) )

// get comments from a resource xxx
r.get( '/comments/:resourceType/:resourceId', optionalAuthorisation, require( './comments/CommentGetFromResource' ) )

// get comment by id
r.get( '/comments/:commentId', optionalAuthorisation, require( './comments/CommentGet' ) )

// edit a comment xxx
r.put( '/comments/:commentId', mandatoryAuthorisation, require( './comments/CommentPut' ) )

// delete a comment xxx
r.delete( '/comments/:commentId', mandatoryAuthorisation, require( './comments/CommentDelete' ) )

Expand Down Expand Up @@ -164,7 +163,12 @@ module.exports = function( app, express, urlRoot ) {
if ( middleware.route )
routes.push( Object.keys( middleware.route.methods ).map( m => m.toUpperCase( ) ) + ': /api' + middleware.route.path )
} )


let serverDescription = {
serverName: process.env.SERVER_NAME,
maxRequestSize: process.env.REQ_SIZE
}

r.get( '/', ( req, res ) => {
serverDescription.routes = routes
serverDescription.version = '1.x.x'
Expand Down
1 change: 0 additions & 1 deletion app/api/v1/streams/StreamGetAll.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict'
const winston = require( 'winston' )
const chalk = require( 'chalk' )
const mongoose = require( 'mongoose' )
Expand Down
4 changes: 1 addition & 3 deletions app/ws/RadioTower.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ const ClientStore = require( './ClientStore' )
const PermissionCheck = require( '../api/v1/middleware/PermissionCheck' )
const DataStream = require( '../../models/DataStream' )

const CONFIG = require( '../../config' )

module.exports = {
subscriber: null,

initRedis( ) {
winston.debug( chalk.magenta( 'Initialising redis in radio tower.' ) )
this.subscriber = redis.createClient( CONFIG.redis.url )
this.subscriber = redis.createClient( process.env.REDIS_URL )
this.subscriber.subscribe( 'speckle-message' )

this.subscriber.on( 'message', ( channel, message ) => {
Expand Down
3 changes: 1 addition & 2 deletions app/ws/SpeckleSockets.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ const clientStore = require( './ClientStore' )
const radioTower = require( './RadioTower' )

const User = require( '../../models/User' )
const CONFIG = require( '../../config' )

module.exports = function( wss ) {

// start a redis subscriber in the radio tower
radioTower.initRedis( )

// start a redis publisher
let redisPublisher = redis.createClient( CONFIG.redis.url )
let redisPublisher = redis.createClient( process.env.REDIS_URL )

redisPublisher.on( 'connect', ( ) => {
winston.debug( `${process.pid} connected to redis.` )
Expand Down
32 changes: 16 additions & 16 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
let serverName = process.env.SPECKLE_NAME ? process.env.SPECKLE_NAME : 'Default Speckle Server'
let maxRequestSize = process.env.REQ_SIZE || '10mb'
// let serverName = process.env.SPECKLE_NAME ? process.env.SPECKLE_NAME : 'Default Speckle Server'
// let maxRequestSize = process.env.REQ_SIZE || '10mb'

module.exports = {
serverDescription: {
serverName: serverName,
maxRequestSize: maxRequestSize,
indentResponses: process.env.INDENT_RESPONSES == 'true' ? true : false
},
mongo: {
url: process.env.MONGODB_URI || process.env.MONGO_URI || 'mongodb://mongo:27017/speckle'
},
redis: {
url: process.env.REDIS_URL || `redis://${process.env.REDIS_ADDR || 'redis'}:${process.env.REDIS_PORT || '6379'}`
},
sessionSecret: 'NaturalSparklingWaterMineral'
}
// module.exports = {
// serverDescription: {
// serverName: serverName,
// maxRequestSize: maxRequestSize,
// indentResponses: process.env.INDENT_RESPONSES == 'true' ? true : false
// },
// mongo: {
// url: process.env.MONGODB_URI || process.env.MONGO_URI || 'mongodb://mongo:27017/speckle'
// },
// redis: {
// url: process.env.REDIS_URL || `redis://${process.env.REDIS_ADDR || 'redis'}:${process.env.REDIS_PORT || '6379'}`
// },
// sessionSecret: 'NaturalSparklingWaterMineral'
// }
3 changes: 1 addition & 2 deletions config/passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ var JwtStrategy = require( 'passport-jwt' ).Strategy
var AnonymousStrategy = require( 'passport-anonymous' )
var ExtractJwt = require( 'passport-jwt' ).ExtractJwt

var sessionSecret = require( '../config' ).sessionSecret
var User = require( '../models/User' )

module.exports = function( passport ) {
let strictOptions = {
jwtFromRequest: ExtractJwt.fromAuthHeaderWithScheme( 'JWT' ),
secretOrKey: sessionSecret
secretOrKey: process.env.SESSION_SECRET
}

// returns 401 Unautorized, protects sensitive routes
Expand Down
13 changes: 0 additions & 13 deletions ecosystem.config.js

This file was deleted.

Loading

0 comments on commit 3c208a2

Please sign in to comment.