-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #149 from Eastern-Research-Group/develop
Deploy to staging.
- Loading branch information
Showing
13 changed files
with
4,686 additions
and
1,248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Production Build | ||
|
||
# Controls when the action will run. | ||
on: | ||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
# Set shared environment variables | ||
env: | ||
APP_VERSION: 2.4.0 | ||
|
||
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | ||
jobs: | ||
build: | ||
# The type of runner that the job will run on | ||
runs-on: ubuntu-latest | ||
environment: production | ||
|
||
# Steps represent a sequence of tasks that will be executed as part of the job | ||
steps: | ||
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | ||
- uses: actions/checkout@v4 | ||
|
||
# Set up node and npm | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: "20" | ||
|
||
- name: Install dependencies | ||
run: npm install --omit=dev | ||
working-directory: app | ||
|
||
- name: Remove unnecessary server app files | ||
run: rm -rf prettier.config.js manifest-dev.yml manifest-staging.yml app/tests | ||
working-directory: app | ||
|
||
- name: Create production artifact | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: lew_v${{ env.APP_VERSION }} | ||
path: app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
cd app | ||
lint-staged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"all": true, | ||
"include": [ | ||
"app/**/*.{ts,js}" | ||
], | ||
"exclude": [ | ||
"**/node_modules/**", | ||
"**/coverage/**", | ||
"**/epa-template-files/**", | ||
"**/tests/**", | ||
"**/api-docs/**" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
const path = require('path'); | ||
const express = require('express'); | ||
const helmet = require('helmet'); | ||
const noCache = require('nocache'); | ||
const cors = require('cors'); | ||
const favicon = require('serve-favicon'); | ||
const basicAuth = require('express-basic-auth'); | ||
const { getEnvironment } = require('./server/utilities/environment'); | ||
const logger = require('./server/utilities/logger'); | ||
const log = logger.logger; | ||
|
||
const app = express(); | ||
|
||
app.use( | ||
helmet({ | ||
contentSecurityPolicy: false, | ||
crossOriginEmbedderPolicy: false, | ||
}), | ||
); | ||
app.use(noCache()); | ||
app.use( | ||
helmet.hsts({ | ||
maxAge: 31536000, | ||
}), | ||
); | ||
|
||
app.use(cors()); | ||
|
||
/**************************************************************** | ||
Which environment | ||
****************************************************************/ | ||
const { isLocal, isTest, isDevelopment, isStaging } = getEnvironment(); | ||
|
||
if (isLocal) { | ||
log.info('Environment = local'); | ||
app.enable('isLocal'); | ||
} else if (isTest) { | ||
log.info('Environment = test'); | ||
app.enable('isTest'); | ||
} | ||
|
||
if (isDevelopment) log.info('Environment = development'); | ||
if (isStaging) log.info('Environment = staging'); | ||
if (!isLocal && !isTest && !isDevelopment && !isStaging) | ||
log.info('Environment = preprod or production'); | ||
|
||
/**************************************************************** | ||
Setup basic auth for non-staging and non-production | ||
****************************************************************/ | ||
if (isDevelopment || isStaging) { | ||
if ( | ||
process.env.LEW_BASIC_AUTH_USER_NAME == null || | ||
process.env.LEW_BASIC_AUTH_USER_PWD == null | ||
) { | ||
log.error( | ||
'Either the basic LEW user name or password environmental variable is not set.', | ||
); | ||
} | ||
|
||
const user_json = | ||
'{"' + | ||
process.env.LEW_BASIC_AUTH_USER_NAME + | ||
'" : "' + | ||
process.env.LEW_BASIC_AUTH_USER_PWD + | ||
'"}'; | ||
const user_obj = JSON.parse(user_json); | ||
|
||
app.use( | ||
basicAuth({ | ||
users: user_obj, | ||
challenge: true, | ||
unauthorizedResponse: getUnauthorizedResponse, | ||
}), | ||
); | ||
} | ||
|
||
function getUnauthorizedResponse(req) { | ||
return req.auth ? 'Invalid credentials' : 'No credentials provided'; | ||
} | ||
|
||
/**************************************************************** | ||
Setup server and routes | ||
****************************************************************/ | ||
app.use( | ||
'/', | ||
express.static(path.join(__dirname, 'public'), { index: ['index.html'] }), | ||
); | ||
app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'))); | ||
|
||
/**************************************************************** | ||
Enable CORS/Preflight/OPTIONS request | ||
****************************************************************/ | ||
app.options('*', cors()); | ||
|
||
/**************************************************************** | ||
Custom application routes | ||
****************************************************************/ | ||
require('./server/routes/index')(app); | ||
|
||
/**************************************************************** | ||
Worst case error handling for 404 and 500 issues | ||
****************************************************************/ | ||
app.use(function (req, res, next) { | ||
res.status(404).sendFile(path.join(__dirname, 'public', '404.html')); | ||
}); | ||
|
||
app.use(function (err, req, res, next) { | ||
res.status(500).sendFile(path.join(__dirname, 'public', '500.html')); | ||
}); | ||
|
||
module.exports = app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// determine which environment we are in | ||
exports.getEnvironment = function () { | ||
let isLocal = false; | ||
let isTest = false; | ||
let isDevelopment = false; | ||
let isStaging = false; | ||
let isProduction = false; | ||
|
||
if (process.env.NODE_ENV) { | ||
isLocal = 'local' === process.env.NODE_ENV.toLowerCase(); | ||
isTest = 'test' === process.env.NODE_ENV.toLowerCase(); | ||
isDevelopment = 'development' === process.env.NODE_ENV.toLowerCase(); | ||
isStaging = 'staging' === process.env.NODE_ENV.toLowerCase(); | ||
isProduction = 'production' === process.env.NODE_ENV.toLowerCase(); | ||
} | ||
|
||
return { | ||
isLocal, | ||
isTest, | ||
isDevelopment, | ||
isStaging, | ||
isProduction, | ||
}; | ||
}; |
Oops, something went wrong.