Last active
April 26, 2018 07:25
-
-
Save kazagkazag/99f8580a30942f3e6194 to your computer and use it in GitHub Desktop.
Simple node server to serve static pages
This file contains hidden or 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
| //npm install express | |
| var express = require('express'); | |
| var app = express(); | |
| var http = require('http'); | |
| app.use(function(req, res, next) { | |
| res.header("Access-Control-Allow-Origin", "*"); | |
| res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); | |
| next(); | |
| }); | |
| app.get('/', function(req, res){ | |
| res.send('<h1>Hello world</h1>'); | |
| }); | |
| //if you have "page" directory and you want to use localhost:3000/index.html adress (index from page directory): | |
| app.use(express.static('page')); | |
| //if you have multiple directories, use localhost:3000/page/index.html and something like below: | |
| //app.use('/page', express.static('page')); | |
| app.listen(3000, function(){ | |
| console.log('listening on *:3000'); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment