-
Notifications
You must be signed in to change notification settings - Fork 2
/
api.ts
30 lines (25 loc) · 819 Bytes
/
api.ts
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
// tslint:disable:no-console
import * as express from 'express';
import { Express, Request, Response } from 'express-serve-static-core';
import * as expressSession from 'express-session';
const app: Express = express();
const port = 8000;
app.use(expressSession({
secret: 'keyboard cat',
resave: false,
saveUninitialized: false,
}));
app.get('/api', (req: Request, res: Response) => {
const session: Express.Session = req.session as Express.Session;
res.send({ value: session.string });
});
app.post('/api/:string?', (req: Request, res: Response) => {
(req.session as Express.Session).string = req.params.string;
res.sendStatus(200);
});
app.listen(port, (err: NodeJS.ErrnoException) => {
if (err) {
throw err;
}
console.info(`API server listening on ${port}`);
});