Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I don't want to use express, just next #334

Closed
ghost opened this issue Jun 4, 2019 · 1 comment
Closed

I don't want to use express, just next #334

ghost opened this issue Jun 4, 2019 · 1 comment

Comments

@ghost
Copy link

ghost commented Jun 4, 2019

I don't want to use express, just next, is there a way to customize this for next only?

const {createServer} = require('http');
const {join} = require('path');
const {parse} = require('url');
const next = require('next');
const routes = require('./src/routes');

const port = parseInt(process.env.PORT, 10) || 4000;
const dev = process.env.NODE_ENV !== 'production';
const app = next({dev});
const handler = routes.getRequestHandler(app);

app.prepare()
    .then(() => {
        createServer((req, res) => {
            const parsedUrl = parse(req.url, true);
            const {pathname} = parsedUrl;

            if (pathname === '/service-worker.js') {
                const filePath = join(__dirname, '.next', pathname);
                app.serveStatic(req, res, filePath)
            } else {
                handler(req, res, parsedUrl)
            }
        }).listen(port, (err) => {
            if (err) throw err;
            console.log(`> Ready on http://localhost:${port}`)
        });
    });

@isaachinman
Copy link
Contributor

Duplicate of #274.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant