2020-01-22 23:47:34 +02:00
|
|
|
require('dotenv').config();
|
|
|
|
import express from 'express';
|
|
|
|
import morgan from 'morgan';
|
|
|
|
import cors from 'cors';
|
|
|
|
import { registerMiddleware as registerLocalGit } from './middlewares/localGit';
|
2020-02-10 18:07:52 +02:00
|
|
|
import { registerMiddleware as registerLocalFs } from './middlewares/localFs';
|
2020-01-22 23:47:34 +02:00
|
|
|
|
|
|
|
const app = express();
|
|
|
|
const port = process.env.PORT || 8081;
|
|
|
|
|
|
|
|
(async () => {
|
|
|
|
app.use(morgan('combined'));
|
|
|
|
app.use(cors());
|
2020-02-11 12:48:02 +02:00
|
|
|
app.use(express.json({ limit: '50mb' }));
|
2020-01-22 23:47:34 +02:00
|
|
|
|
|
|
|
try {
|
2020-02-10 18:07:52 +02:00
|
|
|
const mode = process.env.MODE || 'fs';
|
|
|
|
if (mode === 'fs') {
|
|
|
|
registerLocalFs(app);
|
|
|
|
} else if (mode === 'git') {
|
|
|
|
registerLocalGit(app);
|
|
|
|
} else {
|
|
|
|
throw new Error(`Unknown proxy mode '${mode}'`);
|
|
|
|
}
|
2020-01-22 23:47:34 +02:00
|
|
|
} catch (e) {
|
|
|
|
console.error(e.message);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return app.listen(port, () => {
|
|
|
|
console.log(`Netlify CMS Proxy Server listening on port ${port}`);
|
|
|
|
});
|
|
|
|
})();
|