Last active
June 24, 2018 07:36
-
-
Save AndrejGajdos/203e96fc6c6f7cf185653f80504278c8 to your computer and use it in GitHub Desktop.
Adding required modules and creating new koa application for user authentication project. Whole file is available https://github.com/AndrejGajdos/auth-flow-spa-node-react/blob/master/script/server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('dotenv').config({ path: require('find-config')('.env') }); | |
const Koa = require('koa'); | |
const Router = require('koa-router'); | |
const koaLogger = require('koa-logger'); | |
const cors = require('@koa/cors'); | |
const bodyParser = require('koa-bodyparser'); | |
const serve = require('koa-static'); | |
const send = require('koa-send'); | |
const path = require('path'); | |
const session = require('koa-session'); | |
const redisStore = require('koa-redis'); | |
const ratelimit = require('koa-simple-ratelimit'); | |
const redis = require('redis'); | |
const config = require('./serverConfig'); | |
const includes = require('lodash/includes'); | |
const app = new Koa(); | |
// this last koa middleware catches any request that isn't handled by | |
// koa-static or koa-router, ie your index.html in your example | |
app.use(function* index() { | |
yield send(this, '/dist/index.html'); | |
}); | |
// don't listen to this port if the app is required from a test script | |
if (!module.parent) { | |
app.listen(process.env.PORT || 1337); | |
console.log('app listen on port: 1337'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment