Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(backend): node 19 with fixed image upload #5897

Merged
merged 12 commits into from
Jan 28, 2023
2 changes: 1 addition & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
##################################################################################
# BASE (Is pushed to DockerHub for rebranding) ###################################
##################################################################################
FROM node:12.19.0-alpine3.10 as base
FROM node:19.4.0-alpine3.17 as base

# ENVs
## DOCKER_WORKDIR would be a classical ARG, but that is not multi layer persistent - shame
Expand Down
31 changes: 16 additions & 15 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,22 @@
"linkifyjs": "~2.1.8",
"lodash": "~4.17.14",
"merge-graphql-schemas": "^1.7.8",
"metascraper": "^5.11.8",
"metascraper-audio": "^5.14.26",
"metascraper-author": "^5.14.22",
"metascraper": "^5.33.5",
"metascraper-audio": "^5.33.5",
"metascraper-author": "^5.33.5",
"metascraper-clearbit-logo": "^5.3.0",
"metascraper-date": "^5.11.8",
"metascraper-description": "^5.23.1",
"metascraper-image": "^5.11.8",
"metascraper-lang": "^5.23.1",
"metascraper-date": "^5.33.5",
"metascraper-description": "^5.33.5",
"metascraper-image": "^5.33.5",
"metascraper-lang": "^5.33.5",
"metascraper-lang-detector": "^4.10.2",
"metascraper-logo": "^5.14.26",
"metascraper-publisher": "^5.23.0",
"metascraper-soundcloud": "^5.23.0",
"metascraper-title": "^5.11.8",
"metascraper-url": "^5.14.26",
"metascraper-video": "^5.11.8",
"metascraper-youtube": "^5.23.0",
"metascraper-logo": "^5.33.5",
"metascraper-publisher": "^5.33.5",
"metascraper-soundcloud": "^5.33.5",
"metascraper-title": "^5.33.5",
"metascraper-url": "^5.33.5",
"metascraper-video": "^5.33.5",
"metascraper-youtube": "^5.33.5",
"migrate": "^1.7.0",
"mime-types": "^2.1.26",
"minimatch": "^3.0.4",
Expand Down Expand Up @@ -123,6 +123,7 @@
"supertest": "~4.0.2"
},
"resolutions": {
"fs-capacitor": "6.0.0"
"**/**/fs-capacitor":"^6.2.0",
"**/graphql-upload": "^11.0.0"
}
}
7 changes: 7 additions & 0 deletions backend/src/schema/resolvers/Upload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { GraphQLUpload } from 'graphql-upload'

export default {
// This maps the `Upload` scalar to the implementation provided
// by the `graphql-upload` package.
Upload: GraphQLUpload,
}
9 changes: 5 additions & 4 deletions backend/src/schema/resolvers/images/images.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,11 @@ const localFileUpload = ({ createReadStream, uniqueFilename }) => {
const destination = `/uploads/${uniqueFilename}`
return new Promise((resolve, reject) =>
createReadStream()
.pipe(createWriteStream(`public${destination}`))
.on('finish', () => resolve(destination))
.on('error', reject),
)
.pipe(createWriteStream(`public${destination}`)
.on('finish', () => resolve(destination))
.on('error', (error) => reject(error))
)
)
}

const s3Upload = async ({ createReadStream, uniqueFilename, mimetype }) => {
Expand Down
3 changes: 3 additions & 0 deletions backend/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { RedisPubSub } from 'graphql-redis-subscriptions'
import { PubSub } from 'graphql-subscriptions'
import Redis from 'ioredis'
import bodyParser from 'body-parser'
import { graphqlUploadExpress } from 'graphql-upload'

export const NOTIFICATION_ADDED = 'NOTIFICATION_ADDED'
const { REDIS_DOMAIN, REDIS_PORT, REDIS_PASSWORD } = CONFIG
Expand Down Expand Up @@ -67,6 +68,7 @@ const createServer = (options) => {
},
},
debug: !!CONFIG.DEBUG,
uploads: false,
tracing: !!CONFIG.DEBUG,
formatError: (error) => {
if (error.message === 'ERROR_VALIDATION') {
Expand All @@ -85,6 +87,7 @@ const createServer = (options) => {
app.use(express.static('public'))
app.use(bodyParser.json({ limit: '10mb' }))
app.use(bodyParser.urlencoded({ limit: '10mb', extended: true }))
app.use(graphqlUploadExpress());
server.applyMiddleware({ app, path: '/' })
const httpServer = http.createServer(app)
server.installSubscriptionHandlers(httpServer)
Expand Down
Loading