server.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. const fs = require('fs')
  2. const path = require('path')
  3. const companion = require('../../packages/@uppy/companion')
  4. const app = require('express')()
  5. const DATA_DIR = path.join(__dirname, 'tmp')
  6. app.use(require('cors')({
  7. origin: true,
  8. credentials: true,
  9. }))
  10. app.use(require('cookie-parser')())
  11. app.use(require('body-parser').json())
  12. app.use(require('express-session')({
  13. secret: 'hello planet',
  14. }))
  15. const options = {
  16. providerOptions: {
  17. drive: {
  18. key: process.env.COMPANION_GOOGLE_KEY,
  19. secret: process.env.COMPANION_GOOGLE_SECRET,
  20. },
  21. s3: {
  22. getKey: (req, filename) =>
  23. `whatever/${Math.random().toString(32).slice(2)}/${filename}`,
  24. key: process.env.COMPANION_AWS_KEY,
  25. secret: process.env.COMPANION_AWS_SECRET,
  26. bucket: process.env.COMPANION_AWS_BUCKET,
  27. region: process.env.COMPANION_AWS_REGION,
  28. endpoint: process.env.COMPANION_AWS_ENDPOINT,
  29. },
  30. },
  31. server: { host: 'localhost:3020' },
  32. filePath: DATA_DIR,
  33. secret: 'blah blah',
  34. debug: true,
  35. }
  36. // Create the data directory here for the sake of the example.
  37. try {
  38. fs.accessSync(DATA_DIR)
  39. } catch (err) {
  40. fs.mkdirSync(DATA_DIR)
  41. }
  42. process.on('exit', () => {
  43. fs.rmSync(DATA_DIR, { recursive: true, force: true })
  44. })
  45. app.use(companion.app(options))
  46. const server = app.listen(3020, () => {
  47. console.log('listening on port 3020')
  48. })
  49. companion.socket(server, options)