-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
8 changed files
with
5,086 additions
and
0 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
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,20 @@ | ||
|
||
module.exports = { | ||
webpack: (config, options, webpack) => { | ||
|
||
config.entry = { | ||
index: './server/index.ts' | ||
} | ||
|
||
config.resolve = { | ||
extensions: ['.ts', '.js', '.json'] | ||
} | ||
|
||
config.module.rules.push({ | ||
test: /\.ts$/, | ||
loader: 'awesome-typescript-loader' | ||
}) | ||
|
||
return config | ||
} | ||
} |
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,34 @@ | ||
{ | ||
"name": "nuxtjs-express-admin", | ||
"version": "1.0.0", | ||
"description": "Nuxt.js Express Admin.", | ||
"main": "index.js", | ||
"repository": "https://github.com/kenote/nuxtjs-express-admin.git", | ||
"author": "thondery <thondery@163.com>", | ||
"license": "MIT", | ||
"scripts": { | ||
"dev": "backpack dev" | ||
}, | ||
"dependencies": { | ||
"@types/connect-redis": "^0.0.8", | ||
"body-parser": "^1.18.3", | ||
"compression": "^1.7.3", | ||
"connect-redis": "^3.4.0", | ||
"cookie-parser": "^1.4.3", | ||
"express": "^4.16.4", | ||
"express-session": "^1.15.6", | ||
"method-override": "^3.0.0", | ||
"nunjucks": "^3.1.7" | ||
}, | ||
"devDependencies": { | ||
"@types/compression": "^0.0.36", | ||
"@types/cookie-parser": "^1.4.1", | ||
"@types/express": "^4.16.1", | ||
"@types/express-session": "^1.15.11", | ||
"@types/method-override": "^0.0.31", | ||
"@types/nunjucks": "^3.1.0", | ||
"awesome-typescript-loader": "^5.2.1", | ||
"backpack-core": "^0.8.3", | ||
"typescript": "^3.3.1" | ||
} | ||
} |
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,16 @@ | ||
|
||
import { Config } from '../types/config' | ||
|
||
const project: Config = { | ||
Host: '0.0.0.0', | ||
Port: 4000, | ||
|
||
session_secret: 'kenote_secret', | ||
redis: { | ||
host: '127.0.0.1', | ||
port: 6379, | ||
db: 0 | ||
} | ||
} | ||
|
||
export default project |
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,48 @@ | ||
import * as path from 'path' | ||
import * as http from 'http' | ||
import * as express from 'express' | ||
import * as nunjucks from 'nunjucks' | ||
import * as bodyParser from 'body-parser' | ||
import * as methodOverride from 'method-override' | ||
import * as compress from 'compression' | ||
import * as cookieParser from 'cookie-parser' | ||
import * as session from 'express-session' | ||
import * as connectRedis from 'connect-redis' | ||
|
||
import config from './config' | ||
|
||
const { Host, Port, session_secret, redis } = config | ||
const app: express.Express = express() | ||
const RedisStore: connectRedis.RedisStore = connectRedis(session) | ||
|
||
// 设置模版 | ||
app.set('view', path.resolve(process.cwd(), 'views')) | ||
app.set('view engine', 'njk') | ||
nunjucks.configure('views', { autoescape: true, express: app }) | ||
|
||
// 设置 POST | ||
app.use(bodyParser.json({ limit: '1mb' })) | ||
app.use(bodyParser.urlencoded({ extended: true, limit: '1mb' })) | ||
|
||
// 让服务器能转发 PUT、DELETE 请求 | ||
app.use(methodOverride()) | ||
|
||
// 压缩数据 | ||
app.use(compress()) | ||
|
||
// Cookie | ||
app.use(cookieParser(session_secret)) | ||
|
||
// Session | ||
app.use(session({ | ||
secret: session_secret, | ||
store: new RedisStore(redis), | ||
resave: true, | ||
saveUninitialized: true | ||
})) | ||
|
||
const server: http.Server = http.createServer(app) | ||
server.listen(Port, Host, (err: Error): void => { | ||
if (err) throw err | ||
console.log(`Service running in %s environment, PORT: %d ...`, process.env.NODE_ENV || 'development', 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import * as connectRedis from 'connect-redis' | ||
|
||
export interface Config { | ||
Host?: string | ||
Port: number | ||
|
||
session_secret: string | ||
redis: connectRedis.RedisStoreOptions | ||
} |
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,27 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"lib": [ | ||
"dom", | ||
"es2015" | ||
], | ||
"module": "esNext", | ||
"moduleResolution": "node", | ||
"experimentalDecorators": true, | ||
"emitDecoratorMetadata": true, | ||
"sourceMap": false, | ||
"declaration": false, | ||
"noImplicitAny": false, | ||
"noImplicitThis": false, | ||
"strictNullChecks": true, | ||
"removeComments": true, | ||
"suppressImplicitAnyIndexErrors": true, | ||
"allowSyntheticDefaultImports": true, | ||
"downlevelIteration": true, | ||
"baseUrl": ".", | ||
"allowJs": true, | ||
"paths": { | ||
"~/*": ["./*"] | ||
} | ||
} | ||
} |
Oops, something went wrong.