const express = require("express");
const bodyParser = require("body-parser");
const cors = require("cors");
const session = require("express-session");
const companion = require("@uppy/companion");
const app = express();
const port = 3002;
app.use(bodyParser.json());
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE,OPTIONS");
res.header(
"Access-Control-Allow-Headers",
"Content-Type, Authorization, Content-Length, X-Requested-With, uppy-auth-token"
);
// allows cors preflighting
if ("OPTIONS" === req.method) {
res.sendStatus(200);
}
// Move to next middleware
else {
next();
}
});
app.use(session({ secret: "secret", resave: false, saveUninitialized: false }));
const options = {
providerOptions: {
drive: {
key: "",
secret: "",
},
},
server: {
host: "localhost:3002",
protocol: "http",
// This MUST match the path you specify in `app.use()` below:
path: "/companion",
},
filePath: "files",
secret: "secret",
sendSelfEndpoint: "localhost:3002",
debug: true,
};
const { app: companionApp, emitter } = companion.app(options);
app.use("/companion", companionApp);
app.get("/", (req, res) => {
res.send("Hello World!");
});
const server = app.listen(port);
emitter.on("upload-start", ({ token }) => {
console.log("Upload started", token);
function onUploadEvent({ action, payload }) {
if (action === "success") {
emitter.off(token, onUploadEvent); // avoid listener leak
console.log("Upload finished", token, payload.url);
} else if (action === "error") {
emitter.off(token, onUploadEvent); // avoid listener leak
console.error("Upload failed", payload);
}
}
emitter.on(token, onUploadEvent);
});
companion.socket(server);
This is my settings , I am unable to get companion to work at all . From frontend I keep getting this error GET http://localhost:3002/drive/list/root 404 (Not Found)