-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
38 lines (32 loc) · 1.02 KB
/
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
32
33
34
35
36
37
38
import express from 'express';
import PackageDataHelper from './packageDataHelper.js';
import path from 'path'
import { dirname } from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
var app = express();
app.use(express.static('client'));
app.get('/packages/:package', async function (req, res) {
let pkgName = req.params.package;
let helper = new PackageDataHelper();
try {
let item = await helper.getPackageDataFromRepository(pkgName);
await helper.processPackageDependencies(item);
res.json(item);
}
catch(err) {
let respData = {error:'Error',message:err.message};
res.json(respData);
}
})
app.get('/packages', function(req,res){
res.send('Package dependencies');
})
app.get('/', function(req, res) {
let filePath = path.join(__dirname + '/client/index.html');
res.sendFile(filePath);
});
app.listen(3000, function () {
console.log('Listening on port 3000');
})