Beispiel #1
0
    .then(() => {
        const app = express();
        const port = process.env.PORT || 3000;

        // using default memory store so will be wiped sam way as the db
        app.use(session({
            secret: 'super secret',
            resave: false, // can be false for redis not sure about memoryStore
            saveUninitialized: false,
        }));

        // TODO: PERF: first response is pretty slow because it has to bundle all the things
        // TODO: use tsify to generate correct source maps
        app.get('/static/js/bundle.js', browserify(__dirname + '/../app/main.js', {}));

        // register api routes
        app.use('/api/v1/', api);

        // serve files from the root so no security here, but some stuff is linked directly from node_modules
        app.use('/', express.static(path.join(__dirname, '../'), { maxAge: 31557600000 }));

        // catch all so we serve index on /stats
        app.get('*', (req, res) => {
            res.sendFile(path.join(__dirname, '../index.html'));
        });

        app.listen(
            port,
            function() {
                console.log('Express server listening on port %d', port);
            }
        );

    })
Beispiel #2
0
var browserify = require('browserify-middleware');
var express = require('express');
import path = require("path");

var app = express();

browserify.settings.development('basedir', __dirname);

app.get('/app.js', browserify(['./lib/app']));

app.use(express.static(path.resolve(process.cwd(), 'static')));

app.listen(3000);
console.log("http://127.0.0.1:3000");