Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
persona
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hexang 息壤平台
persona
Commits
5f9c95ed
Commit
5f9c95ed
authored
13 years ago
by
Lloyd Hilaiel
Browse files
Options
Downloads
Patches
Plain Diff
erect a simple mechanism for deployment environment specific configuration
parent
75d03357
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
browserid/app.js
+16
-9
16 additions, 9 deletions
browserid/app.js
browserid/run.js
+1
-0
1 addition, 0 deletions
browserid/run.js
libs/environment.js
+85
-0
85 additions, 0 deletions
libs/environment.js
run.js
+42
-49
42 additions, 49 deletions
run.js
with
144 additions
and
58 deletions
browserid/app.js
+
16
−
9
View file @
5f9c95ed
...
...
@@ -15,11 +15,12 @@ webfinger = require('./lib/webfinger.js'),
sessions
=
require
(
'
cookie-sessions
'
),
express
=
require
(
'
express
'
),
secrets
=
require
(
'
./lib/secrets.js
'
),
db
=
require
(
'
./lib/db.js
'
)
db
=
require
(
'
./lib/db.js
'
),
environment
=
require
(
'
../libs/environment.js
'
),
substitution
=
require
(
'
../libs/substitute.js
'
);
// looks unused, see run.js
// const STATIC_DIR = path.join(path.dirname(__dirname), "static");
const
COOKIE_SECRET
=
secrets
.
hydrateSecret
(
'
cookie_secret
'
,
VAR_DIR
);
const
COOKIE_KEY
=
'
browserid_state
'
;
...
...
@@ -33,7 +34,9 @@ function internal_redirector(new_url) {
function
router
(
app
)
{
app
.
set
(
"
views
"
,
__dirname
+
'
/views
'
);
app
.
set
(
'
view options
'
,
{
production
:
exports
.
production
});
app
.
set
(
'
view options
'
,
{
production
:
app
.
enabled
(
'
use_minified_resources
'
)
});
// this should probably be an internal redirect
// as soon as relative paths are figured out.
...
...
@@ -41,7 +44,7 @@ function router(app) {
res
.
render
(
'
dialog.ejs
'
,
{
title
:
'
A Better Way to Sign In
'
,
layout
:
false
,
production
:
exports
.
production
production
:
app
.
enabled
(
'
use_minified_resources
'
)
});
});
...
...
@@ -109,9 +112,6 @@ function router(app) {
};
exports
.
varDir
=
VAR_DIR
;
exports
.
production
=
true
;
exports
.
setup
=
function
(
server
)
{
server
.
use
(
express
.
cookieParser
());
...
...
@@ -144,7 +144,7 @@ exports.setup = function(server) {
// not awesome, but probably sufficient for now.
req
.
session
.
csrf
=
crypto
.
createHash
(
'
md5
'
).
update
(
''
+
new
Date
().
getTime
()).
digest
(
'
hex
'
);
}
next
();
});
...
...
@@ -172,8 +172,15 @@ exports.setup = function(server) {
}
}
next
();
next
();
});
// configure environment variables based on the deployment target ('NODE_ENV');
environment
.
configure
(
server
);
// add middleware to re-write urls if needed
environment
.
performSubstitution
(
server
);
// add the actual URL handlers other than static
router
(
server
);
}
This diff is collapsed.
Click to expand it.
browserid/run.js
+
1
−
0
View file @
5f9c95ed
...
...
@@ -42,3 +42,4 @@ exports.stopServer = function(cb) {
// when directly invoked from the command line, we'll start the server
if
(
amMain
)
exports
.
runServer
();
This diff is collapsed.
Click to expand it.
libs/environment.js
0 → 100644
+
85
−
0
View file @
5f9c95ed
/*
* An abstraction which contains various pre-set deployment
* environments and adjusts runtime configuration appropriate for
* the current environmnet (specified via the NODE_ENV env var)..
*
* usage is
* exports.configure(app);
*/
const
substitution
=
require
(
'
./substitute.js
'
);
if
(
undefined
===
process
.
env
[
'
NODE_ENV
'
])
{
process
.
env
[
'
NODE_ENV
'
]
=
'
local
'
;
}
exports
.
configure
=
function
(
app
)
{
if
(
!
app
)
throw
"
configure requires express app as argument
"
;
var
known
=
false
;
app
.
enable
(
'
use_minified_resources
'
);
app
.
configure
(
'
production
'
,
function
()
{
app
.
set
(
'
hostname
'
,
'
browserid.org
'
);
app
.
set
(
'
port
'
,
'
443
'
);
app
.
set
(
'
scheme
'
,
'
https
'
);
known
=
true
;
});
app
.
configure
(
'
development
'
,
function
()
{
app
.
set
(
'
hostname
'
,
'
dev.diresworb.org
'
);
app
.
set
(
'
port
'
,
'
443
'
);
app
.
set
(
'
scheme
'
,
'
https
'
);
known
=
true
;
});
app
.
configure
(
'
beta
'
,
function
()
{
app
.
set
(
'
hostname
'
,
'
diresworb.org
'
);
app
.
set
(
'
port
'
,
'
443
'
);
app
.
set
(
'
scheme
'
,
'
https
'
);
known
=
true
;
});
app
.
configure
(
'
local
'
,
function
()
{
app
.
set
(
'
hostname
'
,
'
127.0.0.1
'
);
app
.
set
(
'
port
'
,
'
10001
'
);
app
.
set
(
'
scheme
'
,
'
http
'
);
app
.
disable
(
'
use_minified_resources
'
);
known
=
true
;
});
if
(
!
known
)
throw
"
unknown environment:
"
+
process
.
env
(
'
NODE_ENV
'
);
function
getPortForURL
()
{
if
(
app
.
set
(
'
scheme
'
)
===
'
https
'
&&
app
.
set
(
'
port
'
)
===
'
443
'
)
return
""
;
if
(
app
.
set
(
'
scheme
'
)
===
'
http
'
&&
app
.
set
(
'
port
'
)
===
'
80
'
)
return
""
;
return
"
:
"
+
app
.
set
(
'
port
'
);
}
app
.
set
(
'
URL
'
,
app
.
set
(
'
scheme
'
)
+
'
://
'
+
app
.
set
(
'
hostname
'
)
+
getPortForURL
());
};
/*
* Install middleware that will perform textual replacement on served output
* to re-write urls as needed for this particular environment.
*
* Note, for a 'local' environment, no re-write is needed because this is
* handled at a higher level. For a 'production' env no rewrite is necc cause
* all source files are written for that environment.
*/
exports
.
performSubstitution
=
function
(
app
)
{
if
(
process
.
env
[
'
NODE_ENV
'
]
!==
'
production
'
&&
process
.
env
[
'
NODE_ENV
'
]
!==
'
local
'
)
{
app
.
use
(
substitution
.
substitute
({
'
https://browserid.org
'
:
app
.
set
(
'
URL
'
),
'
browserid.org:443
'
:
app
.
set
(
'
hostname
'
)
+
'
:
'
+
app
.
set
(
'
port
'
),
'
browserid.org
'
:
app
.
set
(
'
hostname
'
)
}));
}
};
This diff is collapsed.
Click to expand it.
run.js
+
42
−
49
View file @
5f9c95ed
...
...
@@ -8,7 +8,8 @@ var sys = require("sys"),
path
=
require
(
"
path
"
),
fs
=
require
(
"
fs
"
),
express
=
require
(
"
express
"
),
substitution
=
require
(
'
./libs/substitute.js
'
);
substitution
=
require
(
'
./libs/substitute.js
'
),
environment
=
require
(
'
./libs/environment.js
'
);
var
PRIMARY_HOST
=
"
127.0.0.1
"
;
...
...
@@ -58,58 +59,54 @@ function substitutionMiddleware(req, resp, next) {
(
substitution
.
substitute
(
subs
))(
req
,
resp
,
next
);
}
function
createServer
(
obj
)
{
var
app
=
express
.
createServer
();
app
.
use
(
express
.
logger
());
var
app
=
express
.
createServer
();
// configure the server based on the environment (NODE_ENV).
environment
.
configure
(
app
);
app
.
use
(
express
.
logger
());
// this file is a *test* harness, to make it go, we'll insert a little handler that
// substitutes output, changing production URLs to developement URLs.
app
.
use
(
substitutionMiddleware
);
// this file is a *test* harness, to make it go, we'll insert a little
// handler that substitutes output, changing production URLs to
// developement URLs.
app
.
use
(
substitutionMiddleware
);
// let the specific server interact directly with the express server to
register their middleware,
// routes, etc...
if
(
obj
.
setup
)
obj
.
setup
(
app
);
// let the specific server interact directly with the express server to
//
register their middleware,
routes, etc...
if
(
obj
.
setup
)
obj
.
setup
(
app
);
// now set up the static resource servin'
var
p
=
obj
.
path
,
ps
=
path
.
join
(
p
,
"
static
"
);
try
{
if
(
fs
.
statSync
(
ps
).
isDirectory
())
p
=
ps
;
}
catch
(
e
)
{
}
app
.
use
(
express
.
static
(
p
));
// now set up the static resource servin'
var
p
=
obj
.
path
,
ps
=
path
.
join
(
p
,
"
static
"
);
try
{
if
(
fs
.
statSync
(
ps
).
isDirectory
())
p
=
ps
;
}
catch
(
e
)
{
}
app
.
use
(
express
.
static
(
p
));
// and listen!
app
.
listen
(
obj
.
port
,
PRIMARY_HOST
);
return
app
;
// and listen!
app
.
listen
(
obj
.
port
,
PRIMARY_HOST
);
return
app
;
};
// start up webservers on ephemeral ports for each subdirectory here.
var
dirs
=
[
// the reference verification server. A version is hosted at
// browserid.org and may be used, or the RP may perform their
// own verification.
{
name
:
"
https://browserid.org/verify
"
,
subPath
:
"
/
"
,
path
:
path
.
join
(
__dirname
,
"
verifier
"
)
},
// An example relying party.
{
name
:
"
http://rp.eyedee.me
"
,
path
:
path
.
join
(
__dirname
,
"
rp
"
)
},
// disabled primary for now since it's not in working
// order.
/* // A reference primary identity provider.
{
name: "https://eyedee.me",
path: path.join(__dirname, "primary")
}, */
// BrowserID: the secondary + ip + more.
{
name
:
"
https://browserid.org
"
,
path
:
path
.
join
(
__dirname
,
"
browserid
"
)
}
// the reference verification server. A version is hosted at
// browserid.org and may be used, or the RP may perform their
// own verification.
{
name
:
"
https://browserid.org/verify
"
,
subPath
:
"
/
"
,
path
:
path
.
join
(
__dirname
,
"
verifier
"
)
},
// An example relying party.
{
name
:
"
http://rp.eyedee.me
"
,
path
:
path
.
join
(
__dirname
,
"
rp
"
)
},
// BrowserID: the secondary + ip + more.
{
name
:
"
https://browserid.org
"
,
path
:
path
.
join
(
__dirname
,
"
browserid
"
)
}
];
function
formatLink
(
server
,
extraPath
)
{
...
...
@@ -132,11 +129,7 @@ dirs.forEach(function(dirObj) {
try
{
var
runJSExists
=
false
;
try
{
runJSExists
=
fs
.
statSync
(
handlerPath
).
isFile
()
}
catch
(
e
)
{};
if
(
runJSExists
)
{
var
runJS
=
require
(
handlerPath
);
// set to development mode
runJS
.
production
=
false
;
}
if
(
runJSExists
)
runJS
=
require
(
handlerPath
);
}
catch
(
e
)
{
console
.
log
(
"
Error loading
"
+
handlerPath
+
"
:
"
+
e
);
process
.
exit
(
1
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment