Skip to content

Commit 7597b41

Browse files
committed
add express backend for manual upload testing
1 parent 3c227c7 commit 7597b41

File tree

6 files changed

+1028
-1
lines changed

6 files changed

+1028
-1
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@ coverage
3030
*.tsbuildinfo
3131

3232

33-
*.tgz
33+
*.tgz
34+
35+
.env

test-apps/express-backend/index.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const express = require('express');
2+
const app = express();
3+
const ImageKit = require('imagekit'); // Node.js SDK
4+
const dotenv = require('dotenv');
5+
dotenv.config();
6+
7+
const imagekit = new ImageKit({
8+
urlEndpoint: 'https://ik.imagekit.io/demo', // https://ik.imagekit.io/your_imagekit_id
9+
publicKey: process.env.IMAGEKIT_PUBLIC_KEY,
10+
privateKey: process.env.IMAGEKIT_PRIVATE_KEY
11+
});
12+
13+
// allow cross-origin requests
14+
app.use(function(req, res, next) {
15+
res.header("Access-Control-Allow-Origin", "*");
16+
res.header("Access-Control-Allow-Headers",
17+
"Origin, X-Requested-With, Content-Type, Accept");
18+
next();
19+
});
20+
21+
app.get('/auth', function (req, res) {
22+
// Your application logic to authenticate the user
23+
// For example, you can check if the user is logged in or has the necessary permissions
24+
// If the user is not authenticated, you can return an error response
25+
const { token, expire, signature } = imagekit.getAuthenticationParameters();
26+
res.send({ token, expire, signature, publicKey: process.env.IMAGEKIT_PUBLIC_KEY });
27+
});
28+
29+
app.listen(3001, function () {
30+
console.log('Live at Port 3001');
31+
});

0 commit comments

Comments
 (0)