server.js 685 B

1234567891011121314151617181920212223242526
  1. const fs = require('fs');
  2. const { createServer } = require('https');
  3. const { parse } = require('url');
  4. const next = require('next');
  5. const dev = process.env.NODE_ENV !== 'production';
  6. const app = next({ dev });
  7. const handle = app.getRequestHandler();
  8. app.prepare().then(() => {
  9. createServer(
  10. {
  11. key: fs.readFileSync('./keys/server.key'),
  12. cert: fs.readFileSync('./keys/server.crt'),
  13. },
  14. (req, res) => {
  15. const parsedUrl = parse(req.url, true);
  16. handle(req, res, parsedUrl);
  17. },
  18. ).listen(3000, (err) => {
  19. if (err) throw err;
  20. // eslint-disable-next-line no-console
  21. console.log('> Server started on https://localhost:3000');
  22. });
  23. });