-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
31 lines (24 loc) · 987 Bytes
/
app.js
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
import {StringTranslator} from "./StringTranslator.js";
import {ImageSearcher} from "./ImageSearcher.js"
import path from 'path';
const __dirname = path.resolve();
import express from "express";
const app = express();
app.use(express.static(__dirname + "/"));
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
//Route to render html file
app.get('/', (req, res) => { res.sendFile(__dirname + '/HTML/picterpret.html')});
//Route to handle StringTranslator requests
app.post('/stringtranslator', function (req, res) {
let strTrans = new StringTranslator(req.body.tradString, req.body.sourceLang, req.body.targetLang);
strTrans.translate(result => {
res.send(result)
});
});
//Route to handle ImageSearcher requests
app.post('/imagesearcher', function (req, res) {
let imgSearch = new ImageSearcher(req.body.imgTerm);
imgSearch.search(result => res.send(result));
});
app.listen(3010, () => console.log('Started on port 3000!'));