Defining routes

Now that we have the required dependencies, we will add the routes. Inside the server outes folder, create a file named cloud-ai-api.ts and update it as follows:

// SNIPP SNIPP
import * as express from 'express';
import * as multer from 'multer';

const UPLOAD_PATH = __dirname + '/../uploads';
const upload = multer({ dest: `${UPLOAD_PATH}/` });

import { Authenticate, Authorize } from '../auth';

import VisionAPI from '../controllers/cloud-ai-api';

export default function defineCloudAIAPIRoutes(app) {
const router = express.Router();
const visionAPI = new VisionAPI();

// Upload Single Images
router.post('/upload-image/:threadId', Authenticate,
Authorize('user'), upload.single('image-reply'), visionAPI.uploadImage);

// Apply the routes to our application with the prefix /api
app.use('/api', router);
}
// SNIPP SNIPP

Here, we have one post route, which accepts an image with a form name of image-reply and forwards that image to visionAPI.checkImage(). Now, we are going to add this route to the list of routes we already have. Update server outes.ts as follows:

// SNIPP SNIPP
import * as express from 'express';
import defineUserRoutes from './routes/user';
import defineThreadRoutes from './routes/thread';
import defineMessageRoutes from './routes/message';
import defineCloudAIAPIRoutes from './routes/cloud-ai-api';

export default function setRoutes(app) {
const router = express.Router();

defineUserRoutes(app);
defineThreadRoutes(app);
defineMessageRoutes(app);
defineCloudAIAPIRoutes(app);
}
// SNIPP SNIPP
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.231.15