-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
50 lines (39 loc) · 1.29 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
import os from "os"
import path from "path"
import express from "express"
import formData from "express-form-data"
import morgan from "morgan"
import { log } from "./logger.js"
import syncEndpoints from "./sync.js"
import asyncEndpoints from "./async.js"
// Set up server
const app = express()
// Attach middleware
app.use(formData.parse({ // parse data with connect-multiparty.
uploadDir: path.join(os.tmpdir(), 'uploads'),
// autoClean: true
}))
app.use(formData.format()) // delete from the request all empty files (size == 0)
// app.use(formData.stream()) // change the file objects to fs.ReadStream
app.use(formData.union()) // union the body and the files
app.use(morgan('tiny')) // logging
app.use((req, res, next) => { console.log('\n\n'); next() }) // add a few line breaks after each request
// GET status
app.get('/status', (req, res) => {
res.json({
message: "iBioSim Server is up and running!"
})
})
// Synchronous endpoints
// POST /sync/convert
// POST /sync/analyze
syncEndpoints(app)
// Asynchronous endpoints
// POST /async/convert
// POST /async/analyze
asyncEndpoints(app)
// Make server listen
const PORT = 4000
app.listen(PORT, () => {
log(`Listening on port ${PORT}`, 'blue', 'Express')
})