Skip to content

Commit 0ca9486

Browse files
committed
add form-vue
1 parent c39a31d commit 0ca9486

24 files changed

+17738
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Start",
6+
"type": "node",
7+
"request": "launch",
8+
"program": "${workspaceRoot}/start.js",
9+
"stopOnEntry": false,
10+
"args": [],
11+
"cwd": "${workspaceRoot}",
12+
"preLaunchTask": null,
13+
"runtimeExecutable": null,
14+
"runtimeArgs": [
15+
"--nolazy", "--use_strict"
16+
],
17+
"env": {
18+
"NODE_ENV": "development"
19+
},
20+
"externalConsole": false,
21+
"sourceMaps": false,
22+
"outDir": null
23+
}
24+
]
25+
}

samples/node/web/vue/form-vue/app.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const Koa = require('koa');
2+
3+
4+
const app = new Koa();
5+
6+
const isProduction = process.env.NODE_ENV === 'production';
7+
8+
// log request URL:
9+
app.use(async (ctx, next) => {
10+
console.log(`Process ${ctx.request.method} ${ctx.request.url}...`);
11+
var
12+
start = new Date().getTime(),
13+
execTime;
14+
await next();
15+
execTime = new Date().getTime() - start;
16+
ctx.response.set('X-Response-Time', `${execTime}ms`);
17+
});
18+
19+
// static file support:
20+
let staticFiles = require('./static-files');
21+
app.use(staticFiles('/static/', __dirname + '/static'));
22+
23+
// redirect to /static/index.html:
24+
app.use(async (ctx, next) => {
25+
ctx.response.redirect('/static/index.html');
26+
});
27+
28+
app.listen(3000);
29+
console.log('app started at port 3000...');
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "view-koa",
3+
"version": "1.0.0",
4+
"description": "koa 2 example with nunjucks as view",
5+
"main": "start.js",
6+
"scripts": {
7+
"start": "node --use_strict start.js"
8+
},
9+
"keywords": [
10+
"vue",
11+
"mvvm"
12+
],
13+
"author": "Michael Liao",
14+
"license": "Apache-2.0",
15+
"repository": {
16+
"type": "git",
17+
"url": "https://github.com/michaelliao/learn-javascript.git"
18+
},
19+
"dependencies": {
20+
"babel-core": "6.13.2",
21+
"babel-polyfill": "6.13.0",
22+
"babel-preset-es2015-node6": "0.3.0",
23+
"babel-preset-stage-3": "6.5.0",
24+
"koa": "2.0.0",
25+
"mime": "1.3.4",
26+
"mz": "2.4.0"
27+
}
28+
}
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require('babel-core/register')({
2+
presets: ['stage-3']
3+
});
4+
5+
require('./app.js');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const path = require('path');
2+
const mime = require('mime');
3+
const fs = require('mz/fs');
4+
5+
function staticFiles(url, dir) {
6+
return async (ctx, next) => {
7+
let rpath = ctx.request.path;
8+
if (rpath.startsWith(url)) {
9+
let fp = path.join(dir, rpath.substring(url.length));
10+
if (await fs.exists(fp)) {
11+
ctx.response.type = mime.lookup(rpath);
12+
ctx.response.body = await fs.readFile(fp);
13+
} else {
14+
ctx.response.status = 404;
15+
}
16+
} else {
17+
await next();
18+
}
19+
};
20+
}
21+
22+
module.exports = staticFiles;

0 commit comments

Comments
 (0)