const express = require('express'); const read = require('./read'); const write = require('./write'); const importFromSS = require('./import-from-ss'); require('dotenv').config(); require('express-async-errors'); const app = express(); const port = process.env.PORT || 3000; app.use(express.json()); app.post('/write', write); app.get('/read/:hash', read); app.post('/importFromSemanticScholar', importFromSS); app.get('*', (req, res) => { console.log(`404 req.path: ${req.path}`); res.status(404).json({ errorCode: 404 }); }); app.use((err, req, res, next) => { const status = err.response?.status ?? 500; const message = err.response?.data?.error ?? err.message; console.error(`error: ${message}`, err); res.status(status).send(message); next(); }); app.listen(port, () => { console.log(`Listening on port ${port}`); });