Created
January 10, 2012 03:55
-
-
Save lyhcode/1586820 to your computer and use it in GitHub Desktop.
iisnode+mongodb samples
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
| var app = require('express').createServer(), | |
| mongoose = require('mongoose'), | |
| db = mongoose.connect('mongodb://localhost/test'); | |
| var renderAsJSON = function (res, obj) { | |
| res.contentType('application/json'); | |
| res.send(JSON.stringify(obj)); | |
| } | |
| // URL Prefix (for iisnode) | |
| var urlPrefix = '/test/express/hello.js'; | |
| // [users] schema, data model | |
| var UserSchema = new mongoose.Schema({ | |
| name: String, | |
| title: String | |
| }); | |
| var UserModel = mongoose.model('users', UserSchema); | |
| //增加一位使用者 | |
| app.get(urlPrefix+'/user/add', function(req, res){ | |
| var result = { | |
| errors: 0, | |
| user: null | |
| }; | |
| var user = new UserModel(); | |
| user.name = req.query.name; | |
| user.title = req.query.title; | |
| user.save(function(err) { | |
| if (err) { | |
| /* skip errors */ | |
| result.errors++; | |
| } | |
| else { | |
| result.user = user; | |
| } | |
| renderAsJSON(res, result); | |
| }); | |
| }); | |
| //列出全部使用者 | |
| app.get(urlPrefix+'/user/list', function(req, res){ | |
| var result = { | |
| errors: 0, | |
| users: [] | |
| }; | |
| UserModel.find({}, function (err, docs) { | |
| if (err) { | |
| result.errors++; | |
| } | |
| else { | |
| result.users = docs; | |
| } | |
| renderAsJSON(res, result); | |
| }); | |
| }); | |
| app.listen(process.env.PORT); |
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
| <configuration> | |
| <system.webServer> | |
| <handlers> | |
| <add name="iisnode" path="hello.js" verb="*" modules="iisnode" /> | |
| </handlers> | |
| <iisnode | |
| node_env="%node_env%" | |
| nodeProcessCountPerApplication="1" | |
| maxConcurrentRequestsPerProcess="1024" | |
| maxNamedPipeConnectionRetry="3" | |
| namedPipeConnectionRetryDelay="2000" | |
| maxNamedPipeConnectionPoolSize="512" | |
| maxNamedPipePooledConnectionAge="30000" | |
| asyncCompletionThreadCount="0" | |
| initialRequestBufferSize="4096" | |
| maxRequestBufferSize="65536" | |
| watchedFiles="*.js" | |
| uncFileChangesPollingInterval="5000" | |
| gracefulShutdownTimeout="60000" | |
| loggingEnabled="true" | |
| logDirectoryNameSuffix="logs" | |
| debuggingEnabled="true" | |
| debuggerPortRange="5058-6058" | |
| debuggerPathSegment="debug" | |
| maxLogFileSizeInKB="128" | |
| appendToExistingLog="false" | |
| logFileFlushInterval="5000" | |
| devErrorsEnabled="true" | |
| flushResponse="false" | |
| /> | |
| <!-- | |
| <iisnode | |
| nodeProcessCommandLine=""%programfiles%\nodejs\node.exe"" /> | |
| --> | |
| <!-- | |
| <rewrite> | |
| <rules> | |
| <rule name="hello"> | |
| <match url="hello/*" /> | |
| <action type="Rewrite" url="hello.js" /> | |
| </rule> | |
| </rules> | |
| </rewrite> | |
| --> | |
| </system.webServer> | |
| </configuration> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment