Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Site
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
24
Issues
24
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Indienet
Site
Commits
efab93dd
Verified
Commit
efab93dd
authored
Mar 17, 2018
by
Aral Balkan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add data file existence states to globals and use them in index.js
parent
06f07519
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
17 deletions
+20
-17
server/globals.js
server/globals.js
+16
-0
server/index.js
server/index.js
+4
-17
No files found.
server/globals.js
View file @
efab93dd
...
...
@@ -3,6 +3,7 @@
const
path
=
require
(
'
path
'
)
const
os
=
require
(
'
os
'
)
const
fs
=
require
(
'
fs-extra
'
)
module
.
exports
=
function
(
app
)
{
const
dataDirectoryPath
=
path
.
join
(
os
.
homedir
(),
'
.indie
'
,
'
site
'
)
...
...
@@ -10,8 +11,23 @@ module.exports = function (app) {
const
ownerKeysFilePath
=
path
.
join
(
dataDirectoryPath
,
'
owner-keys.json
'
)
const
ownerSettingsFilePath
=
path
.
join
(
dataDirectoryPath
,
'
owner-settings.json
'
)
// Ensure that the data directory path exists as other parts of the application
// will rely on it being there.
fs
.
ensureDirSync
(
dataDirectoryPath
)
app
.
set
(
'
dataDirectoryPath
'
,
dataDirectoryPath
)
app
.
set
(
'
serverSecretFilePath
'
,
serverSecretFilePath
)
app
.
set
(
'
ownerKeysFilePath
'
,
ownerKeysFilePath
)
app
.
set
(
'
ownerSettingsFilePath
'
,
ownerSettingsFilePath
)
// Flag whether the various settings files exist or not so that other parts of
// the application can easily query their state (and, if necessary, update it).
const
serverSecretFileExists
=
fs
.
existsSync
(
serverSecretFilePath
)
const
ownerKeysFileExists
=
fs
.
existsSync
(
ownerKeysFilePath
)
const
ownerSettingsFileExists
=
fs
.
existsSync
(
ownerSettingsFilePath
)
app
.
set
(
'
serverSecretFileExists
'
,
serverSecretFileExists
)
app
.
set
(
'
ownerKeysFileExists
'
,
ownerKeysFileExists
)
app
.
set
(
'
ownerSettingsFileExists
'
,
ownerSettingsFileExists
)
}
server/index.js
View file @
efab93dd
/* eslint-disable no-console */
const
logger
=
require
(
'
winston
'
)
const
app
=
require
(
'
./app
'
)
const
portFromConfiguration
=
app
.
get
(
'
port
'
)
const
fs
=
require
(
'
fs-extra
'
)
const
sodium
=
require
(
'
libsodium-wrappers
'
)
const
{
argv
}
=
require
(
'
yargs
'
)
const
app
=
require
(
'
./app
'
)
// Set the port:
//
// 1. Via commandline override (--port) if present
// 2. Via environment variable if present
// 3. Via the Feathers configuration file (fallback)
const
portFromConfiguration
=
app
.
get
(
'
port
'
)
const
port
=
argv
.
port
||
process
.
env
.
PORT
||
portFromConfiguration
// Start the Feathers (API; REST + sockets) server.
...
...
@@ -26,20 +23,11 @@ function startFeathersServer () {
})
}
// File-based data (e.g., configuration, etc.) is saved at ~/.indie/site
const
dataDirectoryPath
=
app
.
get
(
'
dataDirectoryPath
'
)
const
serverSecretFilePath
=
app
.
get
(
'
serverSecretFilePath
'
)
// On first run of the server only, create a server secret. This
// server secret is used to sign the JSON Web Tokens that we use
// for stateless authentication.
async
function
createAndPersitServerSecretIfItDoesntAlreadyExist
()
{
// Check for existence of the file synchronously so as to avoid a possible (if
// highly inprobable) race condition. Since this happens on server start, it
// will not have an impact on performance.
const
serverSecretFileExists
=
fs
.
existsSync
(
serverSecretFilePath
)
if
(
!
serverSecretFileExists
)
{
if
(
!
app
.
get
(
'
serverSecretFileExists
'
))
{
//
// Server secret does not exist. This should be the first time the server
// is being run. Create and save the server.
...
...
@@ -56,8 +44,7 @@ async function createAndPersitServerSecretIfItDoesntAlreadyExist () {
// Write the keys file to a data file in a directory for this spike that
// we place in the home directory of the account that this spike is
// running under.
await
fs
.
ensureDir
(
dataDirectoryPath
)
await
fs
.
writeJson
(
serverSecretFilePath
,
serverSecretObject
)
await
fs
.
writeJson
(
app
.
get
(
'
serverSecretFilePath
'
),
serverSecretObject
)
}
catch
(
error
)
{
throw
new
Error
(
'
Could not persist the server secret.
'
,
error
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment