Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
siibra-explorer
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
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Xiao Gui
siibra-explorer
Commits
6535078d
Commit
6535078d
authored
5 years ago
by
Xiao Gui
Browse files
Options
Downloads
Patches
Plain Diff
chore: cleanify code
parent
bdaa3f0c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
deploy/app.js
+10
-13
10 additions, 13 deletions
deploy/app.js
deploy/compression/index.js
+8
-2
8 additions, 2 deletions
deploy/compression/index.js
with
18 additions
and
15 deletions
deploy/app.js
+
10
−
13
View file @
6535078d
...
...
@@ -66,17 +66,14 @@ app.use('/.well-known', express.static(path.join(__dirname, 'well-known')))
* only use compression for production
* this allows locally built aot to be served without errors
*/
if
(
process
.
env
.
NODE_ENV
===
'
production
'
)
{
const
{
compressionMiddleware
}
=
require
(
'
./compression
'
)
app
.
use
(
compressionMiddleware
,
express
.
static
(
PUBLIC_PATH
))
}
else
{
app
.
use
(
express
.
static
(
PUBLIC_PATH
))
}
app
.
use
((
req
,
res
,
next
)
=>
{
const
{
compressionMiddleware
}
=
require
(
'
./compression
'
)
app
.
use
(
compressionMiddleware
,
express
.
static
(
PUBLIC_PATH
))
const
jsonMiddleware
=
(
req
,
res
,
next
)
=>
{
res
.
set
(
'
Content-Type
'
,
'
application/json
'
)
next
()
}
)
}
const
templateRouter
=
require
(
'
./templates
'
)
const
nehubaConfigRouter
=
require
(
'
./nehubaConfig
'
)
...
...
@@ -84,11 +81,11 @@ const datasetRouter = require('./datasets')
const
pluginRouter
=
require
(
'
./plugins
'
)
const
previewRouter
=
require
(
'
./preview
'
)
app
.
use
(
'
/templates
'
,
templateRouter
)
app
.
use
(
'
/nehubaConfig
'
,
nehubaConfigRouter
)
app
.
use
(
'
/datasets
'
,
datasetRouter
)
app
.
use
(
'
/plugins
'
,
pluginRouter
)
app
.
use
(
'
/preview
'
,
previewRouter
)
app
.
use
(
'
/templates
'
,
jsonMiddleware
,
templateRouter
)
app
.
use
(
'
/nehubaConfig
'
,
jsonMiddleware
,
nehubaConfigRouter
)
app
.
use
(
'
/datasets
'
,
jsonMiddleware
,
datasetRouter
)
app
.
use
(
'
/plugins
'
,
jsonMiddleware
,
pluginRouter
)
app
.
use
(
'
/preview
'
,
jsonMiddleware
,
previewRouter
)
const
catchError
=
require
(
'
./catchError
'
)
app
.
use
(
catchError
)
...
...
This diff is collapsed.
Click to expand it.
deploy/compression/index.js
+
8
−
2
View file @
6535078d
...
...
@@ -30,22 +30,28 @@ exports.detEncoding = detEncoding
exports
.
compressionMiddleware
=
(
req
,
res
,
next
)
=>
{
const
acceptEncoding
=
req
.
get
(
'
Accept-Encoding
'
)
const
encoding
=
detEncoding
(
acceptEncoding
)
// if no encoding is accepted
// or in dev mode, do not use compression
if
(
!
encoding
)
return
next
()
const
ext
=
/
(\.\w
*
?)
$/
.
exec
(
req
.
url
)
// if cannot determine mime-type, do not use encoding
// as Content-Type header is required for browser to understand response
if
(
!
ext
||
!
mimeMap
.
get
(
ext
[
1
]))
return
next
()
res
.
set
(
'
Content-Type
'
,
mimeMap
.
get
(
ext
[
1
]))
if
(
encoding
===
BROTLI
)
{
req
.
url
=
req
.
url
+
'
.br
'
res
.
set
(
'
Content-Encoding
'
,
encoding
)
res
.
set
(
'
Content-Type
'
,
mimeMap
.
get
(
ext
[
1
]))
return
next
()
}
if
(
encoding
===
GZIP
)
{
req
.
url
=
req
.
url
+
'
.gz
'
res
.
set
(
'
Content-Encoding
'
,
encoding
)
res
.
set
(
'
Content-Type
'
,
mimeMap
.
get
(
ext
[
1
]))
return
next
()
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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