-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
36 lines (27 loc) · 1020 Bytes
/
Copy pathserver.js
File metadata and controls
36 lines (27 loc) · 1020 Bytes
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
const Koa = require("koa");
const Router = require("@koa/router");
const session = require("koa-session");
const firebaseAdmin = require('firebase-admin');
const { FirestoreStore } = require("koa-session-firestore");
const FIREBASE_CONFIG = require("./firebase.config.json");
firebaseAdmin.initializeApp({
...FIREBASE_CONFIG,
credential: firebaseAdmin.credential.applicationDefault(),
});
const firestore = firebaseAdmin.firestore();
const app = new Koa();
app.keys = ["some super secret key"];
app.use(session(app, { store: new FirestoreStore({ db: firestore }) }));
const router = new Router();
router.get("/set/:value", async ctx => {
ctx.session.key = ctx.params.value;
ctx.body = `set value to : ${ctx.params.value}`;
});
router.get("/", async ctx => {
ctx.body = `value is: ${ctx.session.key}`;
});
app.use(router.routes());
app.use(router.allowedMethods());
const port = parseInt(process.env.PORT || "3000", 10);
app.listen(port);
console.info(`Server listening at http://localhost:${port}/`);