-
Notifications
You must be signed in to change notification settings - Fork 25
/
index.js
40 lines (34 loc) · 874 Bytes
/
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
const express = require('express');
const app = express();
app.set('json spaces', 5); // to pretify json response
const PORT = 3000;
const fileparser = require('./fileparser');
app.get('/', (req, res) => {
res.send(`
<h2>AWS Educate × 六角學院 2023-05-11 Node.js 直播班</h2>
<form action="/api/upload" enctype="multipart/form-data" method="post">
<div>Select a file:
<input name="file" type="file" />
</div>
<input type="submit" value="Upload" />
</form>
`);
});
app.post('/api/upload', async (req, res) => {
await fileparser(req)
.then(data => {
res.status(200).json({
message: "Success",
data
})
})
.catch(error => {
res.status(400).json({
message: "An error occurred.",
error
})
})
});
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}.`);
})