-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
31 lines (24 loc) · 754 Bytes
/
Copy pathserver.js
File metadata and controls
31 lines (24 loc) · 754 Bytes
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
const http = require('http');
const url = require('url');
const ocrHandler = require('./api/ocr');
const port = process.env.PORT || 3000;
const server = http.createServer(async (req, res) => {
const { pathname } = url.parse(req.url, true);
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'POST, OPTIONS');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
if (req.method === 'OPTIONS') {
res.statusCode = 204;
res.end();
return;
}
if (pathname === '/api/ocr') {
await ocrHandler(req, res);
return;
}
res.statusCode = 404;
res.end('Not found');
});
server.listen(port, () => {
console.log(`OCR server running on http://localhost:${port}`);
});