-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
52 lines (44 loc) · 1.1 KB
/
index.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const path = require('path');
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const dataStore = require('./utils/datastore').dataStore;
const {validateInput, ValidationError} = require('./utils/validator');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static(path.join(__dirname, '../resume-client/build')));
app.post('/api/uploadResumeDetails', (req, res, next) => {
const input = req.body;
const err = validateInput(input);
if (err) {
next(err);
}
const id = dataStore.save(input);
res.json({id});
});
app.get('/api/getResume/:id', (req, res) => {
const id = req.params.id;
const result = dataStore.find(id);
if (result) {
res.json(result);
}
else {
res.json({err: -1});
}
});
// error handlers
app.use((err, req, res, next) => {
if (req.xhr) {
console.log(err);
if (err instanceof ValidationError) {
res.status(500).send({err: err.message});
}
else {
res.status(500).send({err: -500});
}
}
else {
next(err);
}
});
app.listen(5000);