File size: 793 Bytes
efead7f
 
faa2752
804d780
efead7f
 
 
 
 
 
 
 
 
 
804d780
 
 
 
 
 
97458da
804d780
 
 
 
 
 
efead7f
 
97458da
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'use strict';

import express from 'express';
import Lens from 'chrome-lens-ocr';

// Constants
const PORT = 7860;
const HOST = '0.0.0.0';

// App
const app = express();
app.get('/', (req, res) => {
  res.send('Hello World from ExpressJS! This example is from the NodeJS Docs: https://nodejs.org/en/docs/guides/nodejs-docker-webapp/');
});
const lens = new Lens();

app.get('/scanByUrl', async (req, res) => {
  const { url } = req.query;
  try {
    const data = await lens.scanByURL(url);
    const combinedText = data.segments.map(segment => segment.text).join('\n\n');
    res.json({ combinedText, detailedData: data });
  } catch (error) {
    res.status(500).json({ error: error.message });
  }
});

app.listen(PORT, HOST, () => {
  console.log(`Running on http://${HOST}:${PORT}`);
});