Skip to content

Commit 42c90b0

Browse files
committed
further simplify server and do not proxy from s3
1 parent 2d8d9e9 commit 42c90b0

File tree

17 files changed

+33
-649
lines changed

17 files changed

+33
-649
lines changed

.env.example

Lines changed: 0 additions & 4 deletions
This file was deleted.

gatsby-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require('dotenv').config()
44
const path = require('path')
55

6-
const redirectsMiddleware = require('./src/server/middleware/redirects')
6+
const redirectsMiddleware = require('./server/redirect')
77

88
const title = 'Data Version Control · DVC'
99
const description =

lychee.toml

Lines changed: 0 additions & 4 deletions
This file was deleted.

nodemon.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"watch": ["src/server"],
3-
"exec": "node src/server/index.js"
2+
"watch": ["server"],
3+
"exec": "node server/index.js"
44
}

package.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"dev": "gatsby develop",
1010
"clean": "gatsby clean",
1111
"build": "gatsby build",
12-
"start": "node ./src/server/index.js",
12+
"start": "node ./server/index.js",
1313
"start-dev": "nodemon",
1414
"heroku-postbuild": "./scripts/heroku-deploy.sh",
1515
"test": "jest",
@@ -43,14 +43,12 @@
4343
],
4444
"dependencies": {
4545
"@dvcorg/gatsby-theme": "workspace:^",
46-
"@hapi/wreck": "18.1.0",
4746
"@radix-ui/react-dialog": "1.1.15",
4847
"@radix-ui/react-label": "2.1.7",
4948
"@reach/router": "1.3.4",
5049
"@reach/tooltip": "0.18.0",
5150
"@sentry/node": "10.17.0",
5251
"algoliasearch": "4.25.2",
53-
"clsx": "2.1.1",
5452
"compression": "1.8.1",
5553
"dotenv": "17.2.3",
5654
"express": "5.1.0",
@@ -70,7 +68,6 @@
7068
"http-proxy-middleware": "3.0.5",
7169
"isomorphic-fetch": "3.0.0",
7270
"lucide-react": "0.545.0",
73-
"mime-types": "3.0.1",
7471
"nanoid": "5.1.6",
7572
"permissions-policy": "0.6.0",
7673
"promise-polyfill": "8.3.0",
@@ -90,7 +87,6 @@
9087
},
9188
"devDependencies": {
9289
"@aws-sdk/client-cloudfront": "3.901.0",
93-
"@aws-sdk/client-s3": "3.901.0",
9490
"@babel/core": "7.28.4",
9591
"@eslint/eslintrc": "3.3.1",
9692
"@eslint/js": "9.37.0",
@@ -128,7 +124,6 @@
128124
"prettier": "3.6.2",
129125
"remark": "15.0.1",
130126
"remark-html": "16.0.1",
131-
"s3-sync-client": "4.3.1",
132127
"stylelint": "16.25.0",
133128
"stylelint-config-standard": "38.0.0",
134129
"ts-jest": "29.4.4",

scripts/deploy-with-s3.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

scripts/heroku-deploy.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,5 @@ ln -s $NEWPWD $OLDPWD
88
cd $NEWPWD
99
yarn build
1010
rm -rf static .cache
11-
./scripts/deploy-with-s3.js
1211
# Copy the 404 HTML file from public into the root dir for Heroku
13-
cp public/404.html 404.html
1412
./scripts/clear-cloudfront-cache.js

scripts/s3-utils.js

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/server/index.js renamed to server/index.js

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,31 @@
11
/*
2-
* Production server. Proxies to S3 depending on HEROKU_APP_NAME (see
3-
* scripts/deploy-with-s3.js)
2+
* Production server.
43
*
54
* NOTE: This file doesn't go through babel or webpack. Make sure the syntax and
65
* sources this file requires are compatible with the current node version you
76
* are running.
87
*
98
* Required environment variables:
109
*
11-
* - S3_BUCKET: name of the bucket
12-
* - AWS_REGION: region of the bucket
13-
* - AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY: IAM token to access bucket
1410
* - HEROKU_APP_NAME: If this is a PR, an ID of the PR. Don't add this for
1511
* production.
1612
*/
17-
1813
require('./instrument')
14+
require('dotenv').config()
1915

2016
const Sentry = require('@sentry/node')
2117
const compression = require('compression')
2218
const express = require('express')
2319
const helmet = require('helmet')
2420
const { createProxyMiddleware } = require('http-proxy-middleware')
2521
const permissionsPolicy = require('permissions-policy')
22+
const serveHandler = require('serve-handler')
2623

27-
require('dotenv').config()
28-
29-
// eslint-disable-next-line import-x/order
30-
const { s3Url } = require('./config')
24+
const redirectsMiddleware = require('./redirect')
3125

3226
const port = process.env.PORT || 3000
3327
const app = express()
3428

35-
const redirectsMiddleware = require('./middleware/redirects')
36-
const serveMiddleware = require('./middleware/serve')
37-
const { isProduction } = require('./utils')
38-
3929
app.use(compression())
4030
app.use(redirectsMiddleware)
4131
app.use(
@@ -93,6 +83,15 @@ app.use(
9383
})
9484
)
9585
app.use(helmet(helmetOptions))
86+
87+
const serveMiddleware = async (req, res) => {
88+
await serveHandler(req, res, {
89+
public: 'public',
90+
cleanUrls: true,
91+
trailingSlash: false,
92+
directoryListing: false
93+
})
94+
}
9695
app.use(serveMiddleware)
9796
Sentry.setupExpressErrorHandler(app)
9897

@@ -117,10 +116,5 @@ app.use((req, res, _next) => {
117116
})
118117
app.listen(port, () => {
119118
console.log(`Listening on http://localhost:${port}/`)
120-
121-
if (isProduction) {
122-
console.log(`Proxying to ${s3Url}`)
123-
} else {
124-
console.log('Serving static files from local')
125-
}
119+
console.log('Serving static files from local')
126120
})

src/server/instrument.js renamed to server/instrument.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const Sentry = require('@sentry/node')
22

3-
const { parseBoolean } = require('./utils')
3+
const parseBoolean = str => {
4+
return ['True', 'true', '1', true].includes(str)
5+
}
46

57
Sentry.init({
68
dsn: process.env.SENTRY_DSN,

0 commit comments

Comments
 (0)