-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f705c47
commit e91cb37
Showing
7 changed files
with
866 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,6 @@ psd | |
thumb | ||
sketch | ||
|
||
|
||
/build | ||
/server/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const Koa = require("koa"); | ||
const Router = require("koa-router"); | ||
const proxy = require("koa-server-http-proxy"); | ||
const static = require("koa-static"); | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
const router = Router(); | ||
const app = new Koa; | ||
|
||
const PORT = 9876; | ||
|
||
|
||
// views | ||
router.get("/", async (ctx, next) => { | ||
let str = fs.readFileSync(path.resolve(__dirname, "../build/index.html"), "utf-8"); | ||
ctx.response.body = str; | ||
}); | ||
|
||
// 404 | ||
// router.get("*", async (ctx, next) => { | ||
// ctx.response.redirect("/"); | ||
// }) | ||
|
||
app.use(proxy('/api', { | ||
target: 'http://api.douban.com/', | ||
changeOrigin: true, | ||
pathRewrite: { | ||
'^/api': '/v2', // 重写路径 | ||
}, | ||
})); | ||
app.use(proxy('/bing', { | ||
target: 'https://www.bing.com/', | ||
changeOrigin: true, | ||
pathRewrite: { | ||
'^/bing': '/', // 重写路径 | ||
}, | ||
})); | ||
app.use(static(__dirname, "../build")); | ||
app.use(router.routes()); | ||
|
||
app.listen(PORT, () => { | ||
console.log(`http://localhost:${PORT}`); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
{ | ||
"name": "douban-movie", | ||
"name": "douban-movie-server", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"private": true, | ||
"dependencies": { | ||
"koa": "^2.7.0" | ||
"koa": "^2.7.0", | ||
"koa-router": "^7.4.0", | ||
"koa-server-http-proxy": "^0.1.0", | ||
"koa-static": "^5.0.0" | ||
} | ||
} |
Empty file.
Oops, something went wrong.