@@ -7,6 +7,8 @@ const showdown = require('showdown');
7
7
const footnotes = require ( 'showdown-footnotes' ) ;
8
8
const highlight = require ( "showdown-highlight" ) ;
9
9
10
+ const browserSync = require ( "browser-sync" ) ;
11
+
10
12
const express = require ( 'express' ) ;
11
13
const app = express ( ) ;
12
14
const port = 1337 ;
@@ -36,11 +38,6 @@ async function getTemplate() {
36
38
return templateFn ;
37
39
}
38
40
39
- async function renderStep ( step ) {
40
- const html = await renderFile ( `steps/${ step } /README.md` , step ) ;
41
- return html ;
42
- }
43
-
44
41
async function renderFile ( file , step ) {
45
42
const md = readFileSync ( file , { encoding : "utf-8" } ) ;
46
43
const bodyContent = await convertMarkdown ( md ) ;
@@ -49,45 +46,6 @@ async function renderFile(file, step) {
49
46
return html ;
50
47
}
51
48
52
-
53
- /*
54
-
55
- app.get('/', async (req, res) => {
56
- res.redirect(`/README.md`);
57
- });
58
-
59
- app.get('/README.md', async (req, res) => {
60
- try {
61
- const md = readFileSync(`README.md`, { encoding: "utf-8" });
62
- const bodyContent = await convertMarkdown(md);
63
- const templateFn = await getTemplate();
64
- const html = templateFn({ title: `Walkthrough`, bodyContent });
65
- res.send(html);
66
- } catch (error) {
67
- res.status(500).send(error.message);
68
- }
69
- });
70
-
71
- app.get('/steps/:step', async (req, res) => {
72
- res.redirect(`/steps/${req.params.step}/README.md`);
73
- });
74
-
75
- app.get('/steps/:step/README.md', async (req, res) => {
76
- try {
77
- let html;
78
- if (req.params.step === "00") {
79
- html = await renderFile(join(__dirname, "dev-server", "README_AUTHORS.md"), "00");
80
- } else {
81
- html = await renderStep(req.params.step);
82
- }
83
- res.send(html);
84
- } catch (error) {
85
- res.status(500).send(error.message);
86
- }
87
- });
88
- */
89
-
90
-
91
49
app . use ( "/assets" , express . static ( join ( __dirname , ".." , "assets" ) ) ) ;
92
50
93
51
app . use ( "/assets/anchor-js" , express . static ( join ( __dirname , ".." , "node_modules" , "anchor-js" ) ) ) ;
@@ -124,7 +82,8 @@ app.use(async (req, res, next) => {
124
82
} ) ;
125
83
126
84
app . listen ( port , async ( ) => {
127
- console . log ( `Example app listening on port ${ port } ` ) ;
128
- const open = ( await import ( "open" ) ) . default ;
129
- await open ( `http://localhost:${ port } ` ) ;
85
+ browserSync . init ( {
86
+ proxy : `http://localhost:${ port } ` ,
87
+ files : [ "**/*" ] ,
88
+ } ) ;
130
89
} ) ;
0 commit comments