Add basic structure and start server code
This commit is contained in:
parent
4e7e5b7f2f
commit
8f2709ab55
6 changed files with 65 additions and 3 deletions
|
@ -2,12 +2,12 @@
|
|||
"name": "tstatic",
|
||||
"version": "1.0.0",
|
||||
"description": "Container to host simple static applications using a node server, so files can be deployed using rsync",
|
||||
"main": "./src/server.js",
|
||||
"main": "node ./dist/server.js",
|
||||
"bin": {
|
||||
"tstatic": "./src/server.js"
|
||||
"tstatic": "node ./dist/server.js"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "./src/server.js site/",
|
||||
"start": "node ./dist/server.js site/",
|
||||
"postinstall": "typings install",
|
||||
"build": "tsc"
|
||||
},
|
||||
|
|
20
src/server.ts
Normal file
20
src/server.ts
Normal file
|
@ -0,0 +1,20 @@
|
|||
import express from 'express';
|
||||
|
||||
import AccessControl from 'express-ip-access-control';
|
||||
|
||||
import { Options } from './types';
|
||||
|
||||
export default function createServer(opts : Options) {
|
||||
const app = express();
|
||||
|
||||
if (opts.allowed_ips) {
|
||||
app.set('trust proxy', true);
|
||||
app.use(AccessControl({
|
||||
mode: 'allow',
|
||||
allows: opts.allowed_ips,
|
||||
statusCode: 404
|
||||
}));
|
||||
}
|
||||
|
||||
return app;
|
||||
}
|
3
src/types/fakes.d.ts
vendored
Normal file
3
src/types/fakes.d.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
/* Mock types that dont exist */
|
||||
|
||||
declare module 'express-ip-access-control';
|
4
src/types/index.ts
Normal file
4
src/types/index.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
|
||||
export interface Options {
|
||||
allowed_ips: string[];
|
||||
}
|
26
tsconfig.json
Normal file
26
tsconfig.json
Normal file
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"rootDir": "src",
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"noImplicitAny": true,
|
||||
"experimentalDecorators": true,
|
||||
"preserveConstEnums": true,
|
||||
"allowJs": true,
|
||||
"sourceMap": true
|
||||
},
|
||||
"filesGlob": [
|
||||
"typings/index.d.ts",
|
||||
"src/**/*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"dist",
|
||||
"node_modules"
|
||||
],
|
||||
"typeRoots": [
|
||||
"node_modules",
|
||||
"typings",
|
||||
"src/types"
|
||||
],
|
||||
"compileOnSave": false
|
||||
}
|
9
typings.json
Normal file
9
typings.json
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"debug": "registry:npm/debug#2.0.0+20160723033700",
|
||||
"express": "registry:npm/express#4.14.0+20160925001530"
|
||||
},
|
||||
"globalDependencies": {
|
||||
"node": "registry:dt/node#7.0.0+20170204020307"
|
||||
}
|
||||
}
|
Reference in a new issue