feat(api): initial implementation of the auth system (#30)

Adds the auth system but does not add all required features. They will be handled in other tickets
This commit is contained in:
sct
2020-08-28 09:34:15 +09:00
committed by GitHub
parent 7ac4bb01f0
commit 5343f35e5b
10 changed files with 315 additions and 6 deletions

View File

@@ -1,7 +1,12 @@
import express from 'express';
import next from 'next';
import { createConnection } from 'typeorm';
import { createConnection, getRepository } from 'typeorm';
import routes from './routes';
import bodyParser from 'body-parser';
import cookieParser from 'cookie-parser';
import session from 'express-session';
import { TypeormStore } from 'connect-typeorm/out';
import { Session } from './entity/Session';
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
@@ -13,6 +18,23 @@ app
.prepare()
.then(() => {
const server = express();
server.use(cookieParser());
server.use(bodyParser.json());
server.use(bodyParser.urlencoded({ extended: true }));
// Setup sessions
const sessionRespository = getRepository(Session);
server.use(
session({
secret: 'verysecret',
resave: false,
saveUninitialized: false,
store: new TypeormStore({
cleanupLimit: 2,
ttl: 86400,
}).connect(sessionRespository),
})
);
server.use('/api', routes);
server.get('*', (req, res) => handle(req, res));