-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
43 lines (35 loc) · 994 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const express = require('express');
const passport = require('passport');
const dotenv = require('dotenv').config();
const LocalStrategy = require('passport-local').Strategy;
const { logger } = require('./util');
const {
sequelize, init, authenticate, Administrator, Shop
} = require('./database');
const app = express();
async function main() {
if (dotenv.error) {
throw new Error('Environment variables note set!');
}
await authenticate(sequelize);
await init(sequelize);
// authentication
passport.use(new LocalStrategy((username, password, done) => {
// TODO: implement
done();
}));
// routing
app.get('/api/shops', (req, res) =>
Shop.findAll().then((shops) => {
res.send(shops);
}));
app.get('/api/administrators', (req, res) =>
Administrator.findAll().then((administrators) => {
res.send(administrators);
}));
// listen start
app.listen(3000, () => {
logger.log('Server running on port 3000');
});
}
main();