Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require('express');
- const next = require('next');
- const path = require('path');
- const bodyParser = require('body-parser');
- const cors = require('cors');
- const { createProxyMiddleware } = require('http-proxy-middleware');
- const dev = process.env.NODE_ENV !== 'production';
- const app = next({ dir: '.', dev });
- const handle = app.getRequestHandler();
- app.prepare().then(() => {
- const server = express();
- server.use(bodyParser.json({ limit: '50mb' }));
- server.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
- server.use(cors());
- server.use(
- '/images',
- express.static(path.join(__dirname, 'images'), {
- maxAge: dev ? '0' : '365d'
- })
- );
- server.use(
- '/api',
- createProxyMiddleware({
- target: 'https://docs.google.com',
- pathRewrite: { '^/api': '/' },
- changeOrigin: true,
- secure: false
- })
- );
- server.get('*', (req, res) => handle(req, res));
- const PORT = process.env.PORT || 3000;
- server.listen(PORT, err => {
- if (err) throw err;
- console.log(`> Read on http://localhost:${PORT}`);
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement