37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
// Node only has partial ES6 support, import/export is not
|
|
// yet officially supported so we have to use require instead.
|
|
const express = require("express");
|
|
const next = require("next");
|
|
const compression = require("compression");
|
|
//const cookieParser = require('cookie-parser');
|
|
const port = parseInt(process.env.PORT, 10) || 3000;
|
|
const app = next({ dev: process.env.NODE_ENV !== "production" });
|
|
const handle = app.getRequestHandler();
|
|
|
|
// Having trouble with X-origin client side, setup a proxy here
|
|
//const proxy = require('http-proxy-middleware');
|
|
//const EXTERNAL_API = 'http://example.com/api';
|
|
|
|
app.prepare().then(() => {
|
|
const server = express();
|
|
|
|
//const api_proxy = proxy(EXTERNAL_API, { changeOrigin: true });
|
|
// Enable compression locally, helps page load times because... why not.
|
|
server.use(compression());
|
|
|
|
// Parse cookies on the server, which we will pass through to React
|
|
// server.use(cookieParser());
|
|
|
|
// Enable your new proxy below
|
|
// server.use(api_proxy);
|
|
|
|
server.get("*", (req, res) => {
|
|
return handle(req, res);
|
|
});
|
|
|
|
server.listen(port, (err) => {
|
|
if (err) throw err;
|
|
console.log(`💻 Ready on http://localhost:${port}`);
|
|
});
|
|
});
|