mirror of
https://github.com/mapillary/mapillary-js.git
synced 2026-01-18 13:56:53 +00:00
38 lines
999 B
JavaScript
38 lines
999 B
JavaScript
'use strict';
|
|
|
|
import express from 'express';
|
|
import { join } from 'path';
|
|
|
|
const PORT = 8000;
|
|
|
|
const pathname = dirname => {
|
|
const path = join(import.meta.url, `../${dirname}`);
|
|
return new URL(path).pathname;
|
|
}
|
|
|
|
const logger = (req, res, next) => {
|
|
const clearColor = '\x1b[0m';
|
|
res.on('finish', () => {
|
|
const color = res.statusCode === 200 ?
|
|
clearColor : '\x1b[31m';
|
|
const format = `${color}%s${clearColor}`;
|
|
const message = `[${new Date().toISOString()}] ${req.method} ` +
|
|
`${req.path} ${res.statusCode}`;
|
|
console.log(format, message);
|
|
});
|
|
next();
|
|
};
|
|
|
|
const app = express();
|
|
app.use(logger);
|
|
app.use('/', express.static(pathname('examples')));
|
|
app.use('/dist', express.static(pathname('dist')));
|
|
app.get('/examples', (_, res) => { res.redirect('/'); });
|
|
|
|
app.listen(PORT, () => {
|
|
const message =
|
|
`mapillary-js debug server running at ` +
|
|
`http://localhost:${PORT}`;
|
|
console.log(message);
|
|
});
|