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